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