Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotAFile = errors.New("WriteSplitter: invalid memory address or nil pointer dereference") ErrNotADir = errors.New("WriteSplitter: specified dir is not a dir") )
a custom error to signal that no file was closed
Functions ¶
Types ¶
type WriteSplitter ¶
type WriteSplitter struct { Limit int // how many write ops (typically one per line) before splitting the file Dir string // files are named: $prefix + $nano-precision-timestamp + '.log' Prefix string // files are named: $prefix + $nano-precision-timestamp + '.log' Bytes bool // split by bytes and not lines // contains filtered or unexported fields }
WriteSplitter represents a disk bound io.WriteCloser that splits the input across consecutively named files based on either the number of bytes or the number of lines. Splitting does not guarantee true byte/line split precision as it does not parse the incoming data. The decision to split is before the underlying write operation based on the previous invocation. In other words, if a []byte sent to `Write()` contains enough bytes or new lines ('\n') to exceed the given limit, a new file won't be generated until the *next* invocation of `Write()`. If both LineLimit and ByteLimit are set, preference is given to LineLimit. By default, no splitting occurs because both LineLimit and ByteLimit are zero (0).
func ByteSplitter ¶
func ByteSplitter(limit int, dir, prefix string) *WriteSplitter
ByteSplitter returns a WriteSplitter set to split at the given number of bytes
func LineSplitter ¶
func LineSplitter(limit int, dir, prefix string) *WriteSplitter
LineSplitter returns a WriteSplitter set to split at the given number of lines
func (*WriteSplitter) Close ¶
func (ws *WriteSplitter) Close() error
Close is a passthru and satisfies io.Closer. Subsequent writes will return an error.