Documentation ¶
Overview ¶
Package bufwrite provides buffered io.Writer with sync and close methods.
Index ¶
- type BufIOWriter
- type LineWriter
- func (b *LineWriter) Available() int
- func (b *LineWriter) Buffered() int
- func (b *LineWriter) Close() error
- func (b *LineWriter) Flush() error
- func (b *LineWriter) Reset(w io.Writer)
- func (b *LineWriter) Size() int
- func (b *LineWriter) Sync() error
- func (b *LineWriter) Write(p []byte) (nn int, err error)
- func (b *LineWriter) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufIOWriter ¶
BufIOWriter wrap the bufio.Writer, implements the Sync() Close() methods
func NewBufIOWriterSize ¶
func NewBufIOWriterSize(w io.Writer, size int) *BufIOWriter
NewBufIOWriterSize instance with size
type LineWriter ¶
type LineWriter struct {
// contains filtered or unexported fields
}
LineWriter implements buffering for an io.Writer object. If an error occurs writing to a LineWriter, no more data will be accepted and all subsequent writes, and Flush, will return the error. After all data has been written, the client should call the Flush method to guarantee all data has been forwarded to the underlying io.Writer.
from bufio.Writer.
Change:
always keep write full line. more difference please see Write
func NewLineWriter ¶
func NewLineWriter(w io.Writer) *LineWriter
NewLineWriter returns a new LineWriter whose buffer has the default size.
func NewLineWriterSize ¶
func NewLineWriterSize(w io.Writer, size int) *LineWriter
NewLineWriterSize returns a new LineWriter whose buffer has at least the specified size. If the argument io.Writer is already a LineWriter with large enough size, it returns the underlying LineWriter.
func (*LineWriter) Available ¶
func (b *LineWriter) Available() int
Available returns how many bytes are unused in the buffer.
func (*LineWriter) Buffered ¶
func (b *LineWriter) Buffered() int
Buffered returns the number of bytes that have been written into the current buffer.
func (*LineWriter) Flush ¶
func (b *LineWriter) Flush() error
Flush writes any buffered data to the underlying io.Writer.
TIP: please add lock before call the method.
func (*LineWriter) Reset ¶
func (b *LineWriter) Reset(w io.Writer)
Reset discards any un-flushed buffered data, clears any error, and resets b to write its output to w.
func (*LineWriter) Size ¶
func (b *LineWriter) Size() int
Size returns the size of the underlying buffer in bytes.
func (*LineWriter) Write ¶
func (b *LineWriter) Write(p []byte) (nn int, err error)
Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.
func (*LineWriter) WriteString ¶
func (b *LineWriter) WriteString(s string) (int, error)
WriteString to writer