Read bytes from the decompressed stream into p. Returns the number of bytes read and any error that occurred. When the stream is done, io.EOF will be returned.
(p []byte)
| 121 | // Returns the number of bytes read and any error that occurred. |
| 122 | // When the stream is done, io.EOF will be returned. |
| 123 | func (d *Decoder) Read(p []byte) (int, error) { |
| 124 | var n int |
| 125 | for { |
| 126 | if len(d.current.b) > 0 { |
| 127 | filled := copy(p, d.current.b) |
| 128 | p = p[filled:] |
| 129 | d.current.b = d.current.b[filled:] |
| 130 | n += filled |
| 131 | } |
| 132 | if len(p) == 0 { |
| 133 | break |
| 134 | } |
| 135 | if len(d.current.b) == 0 { |
| 136 | // We have an error and no more data |
| 137 | if d.current.err != nil { |
| 138 | break |
| 139 | } |
| 140 | if !d.nextBlock(n == 0) { |
| 141 | return n, d.current.err |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | if len(d.current.b) > 0 { |
| 146 | if debugDecoder { |
| 147 | println("returning", n, "still bytes left:", len(d.current.b)) |
| 148 | } |
| 149 | // Only return error at end of block |
| 150 | return n, nil |
| 151 | } |
| 152 | if d.current.err != nil { |
| 153 | d.drainOutput() |
| 154 | } |
| 155 | if debugDecoder { |
| 156 | println("returning", n, d.current.err, len(d.decoders)) |
| 157 | } |
| 158 | return n, d.current.err |
| 159 | } |
| 160 | |
| 161 | // Reset will reset the decoder the supplied stream after the current has finished processing. |
| 162 | // Note that this functionality cannot be used after Close has been called. |