Documentation ¶
Index ¶
- Constants
- Variables
- func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error
- func HashData(src io.Reader) (string, error)
- func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, error)
- func NewCancelReadCloser(ctx context.Context, in io.ReadCloser) io.ReadCloser
- func NewEagerFileWriter(f *os.File) io.WriteCloser
- func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser
- func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader
- func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func SeekerSize(s io.Seeker) (int64, error)
- func TeeReadCloser(rc io.ReadCloser, w io.Writer) io.ReadCloser
- func TempDir(dir, prefix string) (string, error)
- type AtomicWriteSet
- func (ws *AtomicWriteSet) Cancel() error
- func (ws *AtomicWriteSet) Commit(target string) error
- func (ws *AtomicWriteSet) FileWriter(name string, flag int, perm os.FileMode) (io.WriteCloser, error)
- func (ws *AtomicWriteSet) String() string
- func (ws *AtomicWriteSet) WriteFile(filename string, data []byte, perm os.FileMode) error
- type BytesPipe
- type NopFlusher
- type NopWriter
- type OnEOFReader
- type ReadCloserWrapper
- type ReadSeekCloser
- type WriteCounter
- type WriteFlusher
- Bugs
Constants ¶
const ( SYNC_FILE_RANGE_WAIT_BEFORE = 1 SYNC_FILE_RANGE_WRITE = 2 SYNC_FILE_RANGE_WAIT_AFTER = 4 )
const STEP = 2 * 1024 * 1024 // 2MB
Variables ¶
var ( // ErrClosed is returned when Write is called on a closed BytesPipe. ErrClosed = errors.New("write to closed BytesPipe") )
Functions ¶
func AtomicWriteFile ¶ added in v1.12.0
AtomicWriteFile atomically writes data to a file named by filename.
func NewAtomicFileWriter ¶ added in v1.12.0
NewAtomicFileWriter returns WriteCloser so that writing to it writes to a temporary file and closing it atomically changes the temporary file to destination path. Writing and closing concurrently is not allowed.
func NewCancelReadCloser ¶ added in v1.10.0
func NewCancelReadCloser(ctx context.Context, in io.ReadCloser) io.ReadCloser
NewCancelReadCloser creates a wrapper that closes the ReadCloser when the context is cancelled. The returned io.ReadCloser must be closed when it is no longer needed.
func NewEagerFileWriter ¶
func NewEagerFileWriter(f *os.File) io.WriteCloser
func NewReadCloserWrapper ¶
func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser
NewReadCloserWrapper returns a new io.ReadCloser.
func NewReaderErrWrapper ¶
NewReaderErrWrapper returns a new io.Reader.
func NewWriteCloserWrapper ¶
func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser
NewWriteCloserWrapper returns a new io.WriteCloser.
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopWriteCloser returns a nopWriteCloser.
func TeeReadCloser ¶
func TeeReadCloser(rc io.ReadCloser, w io.Writer) io.ReadCloser
TeeReadCloser returns a ReadCloser that writes to w what it reads from rc. It utilizes io.TeeReader to copy the data read and has the same behavior when reading. Further, when it is closed, it ensures that rc is closed as well.
Types ¶
type AtomicWriteSet ¶ added in v1.13.0
type AtomicWriteSet struct {
// contains filtered or unexported fields
}
AtomicWriteSet is used to atomically write a set of files and ensure they are visible at the same time. Must be committed to a new directory.
func NewAtomicWriteSet ¶ added in v1.13.0
func NewAtomicWriteSet(tmpDir string) (*AtomicWriteSet, error)
NewAtomicWriteSet creates a new atomic write set to atomically create a set of files. The given directory is used as the base directory for storing files before commit. If no temporary directory is given the system default is used.
func (*AtomicWriteSet) Cancel ¶ added in v1.13.0
func (ws *AtomicWriteSet) Cancel() error
Cancel cancels the set and removes all temporary data created in the set.
func (*AtomicWriteSet) Commit ¶ added in v1.13.0
func (ws *AtomicWriteSet) Commit(target string) error
Commit moves all created files to the target directory. The target directory must not exist and the parent of the target directory must exist.
func (*AtomicWriteSet) FileWriter ¶ added in v1.13.0
func (ws *AtomicWriteSet) FileWriter(name string, flag int, perm os.FileMode) (io.WriteCloser, error)
FileWriter opens a file writer inside the set. The file should be synced and closed before calling commit.
func (*AtomicWriteSet) String ¶ added in v1.13.0
func (ws *AtomicWriteSet) String() string
String returns the location the set is writing to.
type BytesPipe ¶ added in v1.9.0
type BytesPipe struct {
// contains filtered or unexported fields
}
BytesPipe is io.ReadWriteCloser which works similarly to pipe(queue). All written data may be read at most once. Also, BytesPipe allocates and releases new byte slices to adjust to current needs, so the buffer won't be overgrown after peak loads.
func NewBytesPipe ¶ added in v1.9.0
func NewBytesPipe() *BytesPipe
NewBytesPipe creates new BytesPipe, initialized by specified slice. If buf is nil, then it will be initialized with slice which cap is 64. buf will be adjusted in a way that len(buf) == 0, cap(buf) == cap(buf).
func (*BytesPipe) Close ¶ added in v1.10.0
Close causes further reads from a BytesPipe to return immediately.
func (*BytesPipe) CloseWithError ¶ added in v1.10.0
CloseWithError causes further reads from a BytesPipe to return immediately.
type NopFlusher ¶
type NopFlusher struct{}
NopFlusher represents a type which flush operation is nop.
type OnEOFReader ¶ added in v1.8.0
type OnEOFReader struct { Rc io.ReadCloser Fn func() }
OnEOFReader wraps an io.ReadCloser and a function the function will run at the end of file or close the file.
func (*OnEOFReader) Close ¶ added in v1.8.0
func (r *OnEOFReader) Close() error
Close closes the file and run the function.
type ReadCloserWrapper ¶
ReadCloserWrapper wraps an io.Reader, and implements an io.ReadCloser It calls the given callback function when closed. It should be constructed with NewReadCloserWrapper
func (*ReadCloserWrapper) Close ¶
func (r *ReadCloserWrapper) Close() error
Close calls back the passed closer function
type ReadSeekCloser ¶
type ReadSeekCloser interface { io.ReadSeeker io.Closer }
ReadSeekCloser combines io.ReadSeeker with io.Closer.
func ConcatReadSeekClosers ¶
func ConcatReadSeekClosers(a, b ReadSeekCloser) (ReadSeekCloser, error)
func NewReadSeekCloserWrapper ¶
func NewReadSeekCloserWrapper(r io.ReadSeeker, closer func() error) ReadSeekCloser
NewReadCloserWrapper returns a new io.ReadCloser.
type WriteCounter ¶ added in v1.7.0
WriteCounter wraps a concrete io.Writer and hold a count of the number of bytes written to the writer during a "session". This can be convenient when write return is masked (e.g., json.Encoder.Encode())
func NewWriteCounter ¶ added in v1.7.0
func NewWriteCounter(w io.Writer) *WriteCounter
NewWriteCounter returns a new WriteCounter.
type WriteFlusher ¶ added in v1.7.0
type WriteFlusher struct {
// contains filtered or unexported fields
}
WriteFlusher wraps the Write and Flush operation ensuring that every write is a flush. In addition, the Close method can be called to intercept Read/Write calls if the targets lifecycle has already ended.
func NewWriteFlusher ¶ added in v1.7.0
func NewWriteFlusher(w io.Writer) *WriteFlusher
NewWriteFlusher returns a new WriteFlusher.
func (*WriteFlusher) Close ¶ added in v1.9.1
func (wf *WriteFlusher) Close() error
Close closes the write flusher, disallowing any further writes to the target. After the flusher is closed, all calls to write or flush will result in an error.
func (*WriteFlusher) Flush ¶ added in v1.7.0
func (wf *WriteFlusher) Flush()
Flush the stream immediately.
func (*WriteFlusher) Flushed ¶ added in v1.7.0
func (wf *WriteFlusher) Flushed() bool
Flushed returns the state of flushed. If it's flushed, return true, or else it return false.
Notes ¶
Bugs ¶
Remove this method. Its use is inherently racy. Seems to be used to detect whether or a response code has been issued or not. Another hook should be used instead.