Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WriteCloser ¶
type WriteCloser struct {
// contains filtered or unexported fields
}
WriteCloser is an io.WriteCloser that buffers output to ensure it only emits bytes to the underlying io.WriteCloser on line feed boundaries.
func NewWriteCloser ¶
func NewWriteCloser(iowc io.WriteCloser, flushThreshold int) (*WriteCloser, error)
NewWriteCloser returns new WriteCloser with the specified flush threshold. Whenever the buffer is greater than the specified threshold, it flushes the buffer, up to and including the final LF byte, to the underlying io.WriteCloser.
func Example() error {
// Flush completed lines to os.Stdout at least every 512 bytes.
lf, err := golfw.NewWriteCloser(os.Stdout, 512)
if err != nil {
return err
}
// Give copy buffer some room.
_, rerr := io.CopyBuffer(lf, os.Stdin, make([]byte, 4096))
// Clean up
cerr := lf.Close()
if rerr == nil {
return cerr
}
return rerr
}
func (*WriteCloser) Close ¶
func (lbf *WriteCloser) Close() error
Close writes all data in its buffer to the underlying io.WriteCloser, including bytes without a trailing LF, then closes the underlying io.WriteCloser. This will either return any error caused by writing the bytes to the underlying io.WriteCloser, or an error caused by closing it. Use this method when done with a WriteCloser to prevent data loss.