writer

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBufSize = 16 * 1024 * 1024 // 16 MiB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedIO

type BufferedIO struct {
	// contains filtered or unexported fields
}

func NewBufferedIO

func NewBufferedIO(
	bufferMaxSize uint64,
	workingDir string,
	fileType FileType,
	zlogger *zap.Logger,
) *BufferedIO

func (*BufferedIO) CloseBoundary

func (s *BufferedIO) CloseBoundary(ctx context.Context) (Uploadeable, error)

func (*BufferedIO) IsWritten

func (s *BufferedIO) IsWritten() bool

func (*BufferedIO) StartBoundary

func (s *BufferedIO) StartBoundary(blockRange *bstream.Range) error

func (BufferedIO) Type

func (b BufferedIO) Type() FileType

func (*BufferedIO) Write

func (s *BufferedIO) Write(data []byte) (n int, err error)

type FileType

type FileType string
const (
	FileTypeJSONL FileType = "jsonl"
	FileTypeCSV   FileType = "csv"
)

type IntelligentWriter

type IntelligentWriter struct {
	*bufio.Writer
	// contains filtered or unexported fields
}

func NewIntelligentWriter

func NewIntelligentWriter(w io.Writer) *IntelligentWriter

NewIntelligentWriter returns a new IntelligentWriter whose buffer has the default size. If the argument io.Writer is already a bufio.Writer with large enough buffer size, it returns the underlying Writer.

func NewIntelligentWriterSize

func NewIntelligentWriterSize(w io.Writer, size int) *IntelligentWriter

NewIntelligentWriterSize is intelligent because it tracks if data was ever written to the temporary file or not. If everything entered the buffer fit in memory, we can nicely optimze away the full I/O operation and avoid all the cost of it.

Operators should specify a buffer as large as they are willing to pay for RAM ( leaving a buffer for "normal" operations of the process).

func (*IntelligentWriter) AllDataFitInMemory

func (w *IntelligentWriter) AllDataFitInMemory() bool

func (*IntelligentWriter) MemoryData

func (w *IntelligentWriter) MemoryData() []byte

type LazyFile

type LazyFile struct {
	*os.File
	// contains filtered or unexported fields
}

LazyFile only creates and writes to file if `Write` is called at least one.

**Important** Not safe for concurrent access, you need to gate yourself if you need that.

func LazyOpen

func LazyOpen(path string) *LazyFile

func (*LazyFile) Close

func (f *LazyFile) Close() error

func (*LazyFile) Path

func (f *LazyFile) Path() string

func (*LazyFile) Write

func (f *LazyFile) Write(p []byte) (n int, err error)

type Uploadeable

type Uploadeable interface {
	Upload(ctx context.Context, store dstore.Store) (string, error)
}

type Writer

type Writer interface {
	io.Writer

	IsWritten() bool
	StartBoundary(*bstream.Range) error
	CloseBoundary(ctx context.Context) (Uploadeable, error)
	Type() FileType
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL