package quicimport ()// readFromChunkSize is the size of the staging buffer ReadFrom copies through.const readFromChunkSize = 64 * 1024// ReadFrom implements [io.ReaderFrom]. It reads from r until EOF or error,// writing to the stream in chunks. Data is copied into stream-owned storage// before each chunk write returns.func ( *SendStream) ( io.Reader) (int64, error) {varint64 := make([]byte, readFromChunkSize)for { , := .Read()if > 0 { , := .Write([:]) += int64()if != nil {return , } }if == io.EOF {return , nil }if != nil {return , } }}// Writev writes the buffers in order. It returns the total number of bytes// written and advances bufs to reflect exactly what was consumed, including a// partially written element, so the caller can resume after a short write.// The stream copies data into owned storage before Writev returns; the caller// may reuse the underlying slices immediately.//// Writev does not hold the stream for the whole vector: another writer may// interleave between elements. The delivered byte stream is identical to the// equivalent sequence of Write calls.//// To send a [net.Buffers], call Writev directly: [net.Buffers] implements// [io.WriterTo], which [io.Copy] prefers over [io.ReaderFrom], so// io.Copy(stream, &bufs) degrades to one Write call per element.func ( *SendStream) ( *net.Buffers) (int64, error) {varint64varerrorfor , := range * {iflen() == 0 {continue }varint , = .Write() += int64()if != nil {break } } := for > 0 && len(*) > 0 {if := int64(len((*)[0])); >= { -= * = (*)[1:]continue } (*)[0] = (*)[0][:] = 0 }if > 0 && len(*) > 0 && == nil { = io.ErrShortWrite }return , }
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.