bufwrite

package
v0.5.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package bufwrite provides buffered io.Writer with sync and close methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufIOWriter

type BufIOWriter struct {
	bufio.Writer
	// contains filtered or unexported fields
}

BufIOWriter wrap the bufio.Writer, implements the Sync() Close() methods

func NewBufIOWriter

func NewBufIOWriter(w io.Writer) *BufIOWriter

NewBufIOWriter instance

func NewBufIOWriterSize

func NewBufIOWriterSize(w io.Writer, size int) *BufIOWriter

NewBufIOWriterSize instance with size

func (*BufIOWriter) Close

func (w *BufIOWriter) Close() error

Close implements the io.Closer

func (*BufIOWriter) Sync

func (w *BufIOWriter) Sync() error

Sync implements the Syncer

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) Close

func (b *LineWriter) Close() error

Close implements the io.Closer

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) Sync

func (b *LineWriter) Sync() error

Sync implements the Syncer

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL