sink

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFile

func NewFile(fsys stream.CreateFS[struct{}], path string) (iosystem.Sink, error)

NewFile creates a sink that writes to a single file. The fs parameter should be a CreateFS filesystem (e.g., from lfs.New or stream.NewFS). Path is passed as-is to fsys.Create() - the client is responsible for proper formatting.

func NewStorage added in v0.1.17

func NewStorage(storage storage.Storage) (iosystem.Sink, error)

NewStorage creates a sink that writes to a filesystem directory. The fs parameter should be a CreateFS filesystem (e.g., from lfs.New or stream.NewFS). Document paths are passed as-is to fsys.Create() - the client is responsible for proper formatting.

Types

type File

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

File writes documents to a single file. All documents are concatenated into one output file with newline separators. The filesystem is provided by the client (e.g., lfs, stream.NewFS).

func (*File) Close

func (f *File) Close() error

Close closes the file and releases resources.

func (*File) Write

func (f *File) Write(ctx context.Context, doc *iosystem.Document) (string, error)

Write appends the document content to the file. The file is created on the first write and kept open until Close().

type FileSystem added in v0.2.0

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

FileSystem writes documents to a filesystem directory. It preserves the document path structure. The filesystem is provided by the client (e.g., lfs, stream.NewFS).

func (*FileSystem) Close added in v0.2.0

func (s *FileSystem) Close() error

Close implements iosystem.Sink.

func (*FileSystem) Write added in v0.2.0

func (s *FileSystem) Write(ctx context.Context, doc *iosystem.Document) (string, error)

Write writes a document to the filesystem, preserving its path structure.

type Writer

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

Writer wraps an io.Writer as a Sink. This is useful for integrating with spool.ForEach or other scenarios where you have an io.Writer and want to use it with Pipeline.

Example with spool:

spool.ForEach(ctx, root, func(ctx, path, r, w) error {
    source := source.NewReaderSource(path, r)
    sink := sink.NewWriterSink(w)
    return pipeline.Run(ctx, source, sink)
})

func NewStdout

func NewStdout() *Writer

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a Sink that writes all documents to the given writer.

func (*Writer) Close

func (s *Writer) Close() error

Close does nothing since WriterSink doesn't own the writer. The writer lifecycle is managed by the caller (e.g., spool).

func (*Writer) Write

func (s *Writer) Write(ctx context.Context, doc *iosystem.Document) (string, error)

Write copies the document content to the underlying writer.

Jump to

Keyboard shortcuts

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