Source File
stream.go
Belonging Package
github.com/valyala/fasthttp
package fasthttp
import (
)
// StreamWriter must write data to w.
//
// Usually StreamWriter writes data to w in a loop (aka 'data streaming').
//
// StreamWriter must return immediately if w returns error.
//
// Since the written data is buffered, do not forget calling w.Flush
// when the data must be propagated to reader.
type StreamWriter func(w *bufio.Writer)
// NewStreamReader returns a reader, which replays all the data generated by sw.
//
// The returned reader may be passed to Response.SetBodyStream.
//
// Close must be called on the returned reader after all the required data
// has been read. Otherwise goroutine leak may occur.
//
// See also Response.SetBodyStreamWriter.
func ( StreamWriter) io.ReadCloser {
:= fasthttputil.NewPipeConns()
:= .Conn1()
:= .Conn2()
var *bufio.Writer
:= streamWriterBufPool.Get()
if == nil {
= bufio.NewWriter()
} else {
= .(*bufio.Writer)
.Reset()
}
go func() {
()
.Flush()
.Close()
streamWriterBufPool.Put()
}()
return
}
var streamWriterBufPool sync.Pool
![]() |
The pages are generated with Golds v0.6.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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |