| 1 | // Package nio provides a few buffered io primitives. |
| 2 | package nioscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/ |
| 3 | |
| 4 | import "ioscip-go gomod github.com/golang/go/src go1.16 io/" |
| 5 | |
| 6 | // Buffer is used to store bytes. |
| 7 | type Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer# interface { |
| 8 | // Len returns how many bytes are buffered |
| 9 | Lenscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#Len.() int64 |
| 10 | |
| 11 | // Cap returns how many bytes can in the buffer at a time |
| 12 | Capscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#Cap.() int64 |
| 13 | |
| 14 | // ReadWriter writes are stored in the buffer, reads return the stored data |
| 15 | ioscip-go gomod github.com/golang/go/src go1.16 io/.ReadWriterscip-go gomod github.com/golang/go/src go1.16 io/ReadWriter# |
| 16 | } |
| 17 | |
| 18 | // Pipe creates a buffered pipe. |
| 19 | // It can be used to connect code expecting an io.Reader with code expecting an io.Writer. |
| 20 | // Reads on one end read from the supplied Buffer. Writes write to the supplied Buffer. |
| 21 | // It is safe to call Read and Write in parallel with each other or with Close. |
| 22 | // Close will complete once pending I/O is done, and may cancel blocking Read/Writes. |
| 23 | // Buffered data will still be available to Read after the Writer has been closed. |
| 24 | // Parallel calls to Read, and parallel calls to Write are also safe : |
| 25 | // the individual calls will be gated sequentially. |
| 26 | func Pipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Pipe().(buf Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#) (r *PipeReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#, w *PipeWriterscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#) { |
| 27 | p := newBufferedPipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/newBufferedPipe().(buf) |
| 28 | r = &PipeReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#{bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeReader#bufpipe.: p} |
| 29 | w = &PipeWriterscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#{bufpipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#bufpipe.: p} |
| 30 | return r, w |
| 31 | } |
| 32 | |
| 33 | // Copy copies from src to buf, and from buf to dst in parallel until |
| 34 | // either EOF is reached on src or an error occurs. It returns the number of bytes |
| 35 | // copied to dst and the first error encountered while copying, if any. |
| 36 | // EOF is not considered to be an error. If src implements WriterTo, it is used to |
| 37 | // write to the supplied Buffer. If dst implements ReaderFrom, it is used to read from |
| 38 | // the supplied Buffer. |
| 39 | func Copyscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Copy().(dst ioscip-go gomod github.com/golang/go/src go1.16 io/.Writerscip-go gomod github.com/golang/go/src go1.16 io/Writer#, src ioscip-go gomod github.com/golang/go/src go1.16 io/.Readerscip-go gomod github.com/golang/go/src go1.16 io/Reader#, buf Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#) (n int64, err error) { |
| 40 | return ioscip-go gomod github.com/golang/go/src go1.16 io/.Copyscip-go gomod github.com/golang/go/src go1.16 io/Copy().(dst, NewReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/NewReader().(src, buf)) |
| 41 | } |
| 42 | |
| 43 | // NewReader reads from the buffer which is concurrently filled with data from the passed src. |
| 44 | func NewReaderscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/NewReader().(src ioscip-go gomod github.com/golang/go/src go1.16 io/.Readerscip-go gomod github.com/golang/go/src go1.16 io/Reader#, buf Bufferscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Buffer#) ioscip-go gomod github.com/golang/go/src go1.16 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.16 io/ReadCloser# { |
| 45 | r, w := Pipescip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/Pipe().(buf) |
| 46 | |
| 47 | go func() { |
| 48 | _, err := ioscip-go gomod github.com/golang/go/src go1.16 io/.Copyscip-go gomod github.com/golang/go/src go1.16 io/Copy().(w, src) |
| 49 | w.CloseWithErrorscip-go gomod github.com/djherbis/nio/v3 . `github.com/djherbis/nio/v3`/PipeWriter#CloseWithError().(err) |
| 50 | }() |
| 51 | |
| 52 | return r |
| 53 | } |