Documentation
¶
Index ¶
- type Buffer
- func (bfr *Buffer) Abort() (err error)
- func (bfr *Buffer) Cleanup() (err error)
- func (bfr *Buffer) Close() (err error)
- func (bfr *Buffer) Read(p []byte) (n int, err error)
- func (bfr *Buffer) Reset()
- func (bfr *Buffer) Stats() stat.Stats
- func (bfr *Buffer) Write(p []byte) (n int, err error)
- func (bfr *Buffer) WriteLine(ln []byte) (err error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements both StatsReadCloser and StatsWriteCloser interfaces.
Buffer is meant to abstract away the details of writing and reading to either a file buffer or in-memory buffer.
Buffer will: - compress writes if Options.Compress is true. - keep track of buffer statistics - calculate MD5 checksum on calling Close() - calculate the buffer size - provide the tmp file path in the file stats. - clean up tmp file if Abort() or Cleanup() are called.
func (*Buffer) Abort ¶
Abort will clear the buffer (remove tmp file if exists) and prevent further buffer writes.
func (*Buffer) Cleanup ¶
Cleanup will remove the tmp file (if exists) or reset the in-memory buffer (if used).
Cleanup should not be used until the user is done with the contents of the buffer.
Cleanup is called automatically as part of the abort process but since the user may wish to read from the buffer after closing, Cleanup will need to be called after Close, especially if using compression since Close flushes the compression buffer and finalizes writing.
func (*Buffer) Read ¶
Read will read the raw underlying buffer bytes. If the buffer is writing with compression it will not decompress on reads. Read is made for reading the final written bytes and copying them to the final location.
Close should be called before Read as Close will sync the underlying buffer. This is especially important when using compression and/or a tmp file.
func (*Buffer) Reset ¶ added in v0.4.0
func (bfr *Buffer) Reset()
Reset will reset the in-memory buffer (if used) and remove the reference to the tmp file (if exists)
Reset does not verify that the tmp file is closed
type Options ¶
type Options struct {
// UseFileBuf specifies to use a tmp file for the delayed writing.
// Can optionally also specify the tmp directory and tmp name
// prefix.
UseFileBuf bool
// FileBufDir optionally specifies the temp directory. If not specified then
// the os default temp dir is used.
FileBufDir string
// FileBufPrefix optionally specifies the temp file prefix.
// The full tmp file name is randomly generated and guaranteed
// not to conflict with existing files. A prefix can help one find
// the tmp file.
FileBufPrefix string
// Compress set to true will turn on gzip compression.
// Writes will be compressed but reads will read raw
// compressed bytes.
Compress bool
// CompressLevel type of compression used on the file
// gzip.BestSpeed = 1 // quick but very little compression
// gzip.BestCompression = 9 // smallest size but takes longer
// gzip.DefaultCompression = -1 // balance between speed and size
CompressLevel int
// KeepFailed files when using a file buffer and the
// copy commands fails
KeepFailed bool
}
func NewOptions ¶
func NewOptions() *Options