New creates a new AsyncBuffer that reads from the given io.ReadCloser in background and closes it when finished. r - io.ReadCloser to read data from dataLen - expected length of the data in r, <= 0 means unknown length finishFn - optional functions to call when the buffer is finished reading
(r io.ReadCloser, dataLen int, finishFn ...context.CancelFunc)
| 84 | // dataLen - expected length of the data in r, <= 0 means unknown length |
| 85 | // finishFn - optional functions to call when the buffer is finished reading |
| 86 | func New(r io.ReadCloser, dataLen int, finishFn ...context.CancelFunc) *AsyncBuffer { |
| 87 | ab := &AsyncBuffer{ |
| 88 | r: r, |
| 89 | dataLen: dataLen, |
| 90 | paused: NewLatch(), |
| 91 | chunkCond: NewCond(), |
| 92 | finishFn: finishFn, |
| 93 | } |
| 94 | |
| 95 | go ab.readChunks() |
| 96 | |
| 97 | return ab |
| 98 | } |
| 99 | |
| 100 | // NewReadFull creates a new AsyncBuffer that reads from the given io.ReadCloser |
| 101 | // in foreground, blocking until all data is read. It returns an error if reading |