writesplitter

package module
Version: v0.0.0-...-ee4caf0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2016 License: BSD-3-Clause Imports: 4 Imported by: 0

README

GoDoc Go Report Card

An io.WriteCloser that creates files of a certain size.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func CheckDir

func CheckDir(dir string) error

CheckDir ensure that the given dir exists and is a dir

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.

func (*WriteSplitter) Write

func (ws *WriteSplitter) Write(p []byte) (int, error)

Write satisfies io.Writer and internally manages file io. Write also limits each WriteSplitter to only one open file at a time.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL