Documentation
¶
Overview ¶
package io implements various io utilities.
Index ¶
- Constants
- Variables
- func CleanupSessionFolderIfNeeded()
- func CreateTempFolder(name string, perm os.FileMode) (string, error)
- func NewBufferedPipe() (io.ReadCloser, io.WriteCloser)
- func NewBufferedPipeWithMaxSize(maxSize uint) (io.ReadCloser, io.WriteCloser)
- func NewTimestampAwareReader(inner io.Reader, opts TimestampAwareReaderOptions) io.ReadCloser
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
- func OpenTempFile(name string, flag int, perm os.FileMode) (*os.File, error)
- func PreserveSessionFolder()
- func WriteFile(name string, data []byte, perm os.FileMode) error
- type BufferedPipeReader
- type BufferedPipeWriter
- type BufferedWrappingWriter
- type ContextReader
- type FollowWriter
- type FollowWriterOption
- type IndexLine
- type IndexingWriter
- type NotifyWriteCloser
- type ParagraphWriter
- type Syncer
- type TailReader
- type TailReaderStats
- type TarWriter
- func (tw *TarWriter) Buffer() (*bytes.Buffer, error)
- func (tw *TarWriter) CopyFile(src io.Reader, size int64, name string, uid int32, gid int32, mode os.FileMode, ...) error
- func (tw *TarWriter) WriteDir(name string, uid int32, gid int32, mode os.FileMode, modTime time.Time, ...) error
- func (tw *TarWriter) WriteFile(contents []byte, name string, uid int32, gid int32, mode os.FileMode, ...) error
- func (tw *TarWriter) WriteSymlink(name string, linkTarget string, uid int32, gid int32, modTime time.Time, ...) error
- type TimestampAwareReaderOptions
- type WriteSyncerCloser
Constants ¶
const ( DCP_SESSION_FOLDER = "DCP_SESSION_FOLDER" // Folder to delete when finished with a session DCP_PRESERVE_EXECUTABLE_LOGS = "DCP_PRESERVE_EXECUTABLE_LOGS" // If truthy ("1", "true", "on", "yes"), preserve logs from executable runs )
const (
FirstLogLineNumber = 1
)
const (
MaxTailSize = 1000 * 1000 // Million rows
)
Variables ¶
var ( ErrClosedWriter = errors.New("writer is closed") ErrClosedReader = errors.New("reader is closed") )
var (
DcpSessionDir func() string
)
var (
DcpTempDir func() string
)
Functions ¶
func CleanupSessionFolderIfNeeded ¶
func CleanupSessionFolderIfNeeded()
func NewBufferedPipe ¶
func NewBufferedPipe() (io.ReadCloser, io.WriteCloser)
NewBufferedPipe is like io.Pipe(), except it includes an automatically-expanding buffer, so writers are never blocked. It is also goroutine-safe. Inspiration/reference: https://github.com/golang/go/issues/28790, https://github.com/golang/go/issues/34502, https://github.com/acomagu/bufpipe
func NewBufferedPipeWithMaxSize ¶ added in v0.22.2
func NewBufferedPipeWithMaxSize(maxSize uint) (io.ReadCloser, io.WriteCloser)
NewBufferedPipeWithMaxSize is like NewBufferedPipe, but with an optional maximum buffer size. If maxSize is 0, the buffer can grow without limit (same as NewBufferedPipe). If maxSize is > 0, writers will block when the buffer reaches the maximum size, waiting for readers to consume data before more can be written.
func NewTimestampAwareReader ¶
func NewTimestampAwareReader(inner io.Reader, opts TimestampAwareReaderOptions) io.ReadCloser
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
func PreserveSessionFolder ¶
func PreserveSessionFolder()
Types ¶
type BufferedPipeReader ¶
type BufferedPipeReader struct {
// contains filtered or unexported fields
}
func (*BufferedPipeReader) Close ¶
func (bpr *BufferedPipeReader) Close() error
Closes the reader half of the pipe, subsequent readers will receive io.ErrClosedPipe.
func (*BufferedPipeReader) CloseWithError ¶
func (bpr *BufferedPipeReader) CloseWithError(err error) error
Closes the reader half of the pipe, subsequent readers will receive the passed error. PipeReader spec requires that CloseWithError() never overwrites the previous error and always returns nil.
type BufferedPipeWriter ¶
type BufferedPipeWriter struct {
// contains filtered or unexported fields
}
func (*BufferedPipeWriter) Close ¶
func (bpw *BufferedPipeWriter) Close() error
Closes the writer half of the pipe, subsequent writers will receive io.ErrClosedPipe. Subsequent readers will receive io.EOF.
func (*BufferedPipeWriter) CloseWithError ¶
func (bpw *BufferedPipeWriter) CloseWithError(err error) error
Closes the writer half of the pipe, subsequent writers will receive the passed error. Subsequent readers will receive io.EOF. PipeWriter spec requires that CloseWithError() never overwrites the previous error and always returns nil.
type BufferedWrappingWriter ¶
type BufferedWrappingWriter struct {
// contains filtered or unexported fields
}
func NewBufferedWrappingWriter ¶
func NewBufferedWrappingWriter() *BufferedWrappingWriter
Creates a new BufferedWrappingWriter.
func (*BufferedWrappingWriter) Close ¶
func (bww *BufferedWrappingWriter) Close() error
type ContextReader ¶
type ContextReader struct {
// contains filtered or unexported fields
}
ContextReader is a reader that will read from an inner reader until the context is cancelled.
func NewContextReader ¶
Creates a new ContextReader instance If leverageReadCloser is true, the ContextReader will take advantage of the fact that the reader is also a ReadCloser and will call Close() on the reader when the context is cancelled. This allows the ContextReader to work without extra worker goroutine. The user of the ContextReader must ensure that the reader is not closed by other means.
type FollowWriter ¶
type FollowWriter struct {
// contains filtered or unexported fields
}
func NewFollowWriter ¶
func NewFollowWriter(ctx context.Context, source io.Reader, dest io.Writer, opts ...FollowWriterOption) *FollowWriter
Creates a FollowWriter that reads content from the reader source and writes it to the writer destination. Keeps trying to read new content even after EOF until StopFollow() is called, after which the next EOF received will cause the reader and writer to stop. If the source is an io.Closer, it will be closed when the FollowWriter is cancelled.
Use WithNoDataStopRetries option to specify extra read attempts after StopFollow() is called when no data has been seen yet. This is useful when the data source might not be ready immediately.
func (*FollowWriter) Cancel ¶
func (fw *FollowWriter) Cancel()
func (*FollowWriter) Done ¶
func (fw *FollowWriter) Done() <-chan struct{}
func (*FollowWriter) Err ¶
func (fw *FollowWriter) Err() error
func (*FollowWriter) StopFollow ¶
func (fw *FollowWriter) StopFollow()
type FollowWriterOption ¶ added in v0.22.8
type FollowWriterOption func(*FollowWriter)
FollowWriterOption is a functional option for the FollowWriter.
func WithNoDataStopRetries ¶ added in v0.22.8
func WithNoDataStopRetries(n uint) FollowWriterOption
WithNoDataStopRetries sets the number of extra read attempts the FollowWriter will make after StopFollow() is called, but only if it has never read any data. If the FollowWriter has already seen data when StopFollow() is called, it stops immediately after zero-byte read or EOF is encountered.
type IndexingWriter ¶
type IndexingWriter struct {
// contains filtered or unexported fields
}
func NewIndexingWriter ¶
func NewIndexingWriter(data, index WriteSyncerCloser) *IndexingWriter
func NewIndexingWriterWithStride ¶
func NewIndexingWriterWithStride(data, index WriteSyncerCloser, indexStride uint32) *IndexingWriter
func (*IndexingWriter) Close ¶
func (iw *IndexingWriter) Close() error
func (*IndexingWriter) IndexInvalid ¶
func (iw *IndexingWriter) IndexInvalid() bool
func (*IndexingWriter) Sync ¶
func (iw *IndexingWriter) Sync() error
type NotifyWriteCloser ¶
type NotifyWriteCloser interface {
WriteSyncerCloser
Closed() <-chan struct{}
}
NotifiyWriteCloser is a WriteCloser that can notify when it is closed.
func NewContextWriteCloser ¶
func NewContextWriteCloser(ctx context.Context, w WriteSyncerCloser) NotifyWriteCloser
type ParagraphWriter ¶
type ParagraphWriter interface {
io.WriteCloser
NewParagraph()
}
ParagraphWriter is a WriteCloser that writes to an inner WriteCloser and has a concept of "paragraphs of data". A new paragraph is started by calling NewParagraph(). When that happens, the NEXT write (the first write of a new paragraph) will be preceded by a paragraph separator.
func NewParagraphWriter ¶
func NewParagraphWriter(w io.WriteCloser, paragraphSeparator []byte) ParagraphWriter
type TailReader ¶
type TailReader struct {
// Set (frozen) when tailLines is filled with data and the reader stats are available.
Filled *concurrency.AutoResetEvent
FillStats *atomic.Pointer[TailReaderStats] // The stats of the reader
// contains filtered or unexported fields
}
TailReader is an io.ReadCloser that returns the last N lines of text from an inner reader. It reads all content from the inner reader until EOF, then allows reading only the last N lines from it. If the inner reader contains fewer than N lines, all lines will be returned.
TailReader remains usable after EOF is reached, i.e. it will just delegate to the inner reader once the last N lines are returned.
TailReader is not thread-safe, except from the Filled event and the Stats atomic pointer. The Stats value is valid only after the Filled event is set.
func NewTailReader ¶
func NewTailReader(inner io.ReadCloser, tailSize int) *TailReader
func (*TailReader) Close ¶
func (tr *TailReader) Close() error
Close implements the io.Closer interface.
type TailReaderStats ¶
type TarWriter ¶
type TarWriter struct {
// contains filtered or unexported fields
}
func NewTarWriter ¶
func NewTarWriter() *TarWriter
type WriteSyncerCloser ¶
type WriteSyncerCloser interface {
io.WriteCloser
Syncer
}
func NewTimestampWriter ¶
func NewTimestampWriter(inner WriteSyncerCloser) WriteSyncerCloser
Creates a new TimestampWriter that wraps the given writer.