Documentation
¶
Index ¶
- Constants
- Variables
- func Configure(config Config) error
- func Do[T any](ctx context.Context, fn func(s *Scope) (*T, error)) (*T, error)
- func JoinCleanup(fns ...func() error) func() error
- func MB(size int64) int64
- func Read(ctx context.Context, src Source, fn func(r io.Reader) error) error
- func ReadAt(ctx context.Context, src Source, fn func(ra io.ReaderAt, size int64) error, ...) error
- func ReadAtResult[T any](ctx context.Context, src Source, ...) (*T, error)
- func ReadFileLines(ctx context.Context, path string, fn LineFunc) error
- func ReadLines(ctx context.Context, src Source, fn LineFunc) error
- func ReadList(ctx context.Context, srcs []Source, fn func(readers []io.Reader) error) error
- func ReadListResult[T any](ctx context.Context, srcs []Source, fn func(readers []io.Reader) (*T, error)) (*T, error)
- func ReadResult[T any](ctx context.Context, src Source, fn func(r io.Reader) (*T, error)) (*T, error)
- func SafeClose(c io.Closer)
- func Size(ctx context.Context, src Source) (int64, error)
- func SizeAny(x any) int64
- func SizeFromStream(src Source) int64
- func SizeFromStreamList(srcs []Source) int64
- func ToExt(format string) string
- func WithMaxPreallocate(bytes int64) maxPreallocateOption
- func WithMmap(enabled bool) mmapOption
- func WithSession(ctx context.Context, ses IoSession) context.Context
- func WithSpillThreshold(bytes int64) spillThresholdOption
- func WithThreshold(bytes int64) thresholdOption
- func WriteFile(r io.Reader, path string) (int64, error)
- func WriteStreamToFile(src Source, path string) (int64, error)
- type Config
- type DownloadReaderCloser
- type InOption
- type Input
- type IoManager
- type IoSession
- type LineFunc
- type ManagerOption
- type ManagerOptionFunc
- type OutConfig
- type OutHandle
- type OutOption
- type OutOptionFunc
- type OutReuseOpt
- type OutReuseOptFunc
- type OutScope
- type Output
- func Copy(ctx context.Context, src Source, out OutConfig) (*Output, error)
- func DoOut(ctx context.Context, outCfg OutConfig, ...) (*Output, error)
- func DoOutResult[T any](ctx context.Context, outCfg OutConfig, ...) (*Output, *T, error)
- func Process(ctx context.Context, src Source, out OutConfig, ...) (*Output, error)
- func ProcessAt(ctx context.Context, src Source, out OutConfig, ...) (*Output, error)
- func ProcessAtResult[T any](ctx context.Context, src Source, out OutConfig, ...) (*Output, *T, error)
- func ProcessList(ctx context.Context, srcs []Source, out OutConfig, ...) (*Output, error)
- func ProcessListResult[T any](ctx context.Context, srcs []Source, out OutConfig, ...) (*Output, *T, error)
- func ProcessResult[T any](ctx context.Context, src Source, out OutConfig, ...) (*Output, *T, error)
- func (o *Output) Bytes() ([]byte, error)
- func (o *Output) Data() []byte
- func (o *Output) Keep() *Output
- func (o *Output) OpenReader() (io.ReadCloser, error)
- func (o *Output) OpenWriter(sizeHint ...int64) (io.WriteCloser, error)
- func (o *Output) Path() string
- func (o *Output) SaveAs(path string) error
- func (o *Output) Size() int64
- func (o *Output) StorageType() StorageType
- func (o *Output) WriteTo(w io.Writer) (int64, error)
- type ReaderAtResult
- type Scope
- type Source
- func BytesSource(b []byte) Source
- func FileSource(f *os.File) Source
- func In(src Source, opts ...InOption) Source
- func InputSource(in *Input) Source
- func MultipartSource(fh *multipart.FileHeader) Source
- func OutputSource(o *Output) Source
- func PathSource(p string) Source
- func ReadCloserSource(rc io.ReadCloser) Source
- func ReaderSource(r io.Reader) Source
- func URLSource(u string) Source
- type StorageType
- type ToReaderAtOption
- type ToReaderAtOptions
- type Void
Constants ¶
const ( Json = ".json" Csv = ".csv" Txt = ".txt" Xml = ".xml" Pdf = ".pdf" Docx = ".docx" Xlsx = ".xlsx" Pptx = ".pptx" Jpg = ".jpg" Jpeg = ".jpeg" Png = ".png" Zip = ".zip" )
const ( KindFile = "file" KindURL = "url" KindMultipart = "multipart" KindMemory = "memory" KindReader = "reader" KindStream = "stream" )
const DefaultBaseTempDir = "./temp"
Variables ¶
var ( ErrNilSource = errors.New("fio: nil source") ErrIoManagerClosed = errors.New("fio: manager is closed") ErrIoSessionClosed = errors.New("fio: session is closed") ErrDownloadFailed = errors.New("fio: download failed") ErrNoSession = errors.New("fio: session is nil") ErrInvalidSessionType = errors.New("fio: invalid session type") ErrNilFunc = errors.New("fio: fn is nil") ErrEmptyPath = errors.New("fio: empty path") ErrEmptyURL = errors.New("fio: empty url") ErrOutputCleaned = errors.New("fio: output is cleaned up") ErrNilOutHandle = errors.New("fio: nil OutHandle") ErrNilOutScope = errors.New("fio: nil out-scope") ErrNewOutMultiple = errors.New("fio: NewOut called more than once") ErrOutReuseRequiresPtr = errors.New("fio: OutReuse requires out pointer") ErrCannotGetReaderAt = errors.New("fio: cannot get ReaderAt") ErrInputNotReusable = errors.New("fio: input is not reusable") ErrCannotResetInput = errors.New("fio: cannot reset input") ErrToReaderAtNilReader = errors.New("fio: ToReaderAt: nil reader") ErrNilInput = errors.New("fio: nil input") )
Functions ¶
func JoinCleanup ¶
func ReadAtResult ¶
func ReadListResult ¶
func ReadResult ¶
func SizeFromStream ¶
SizeFromStream returns size for a type-safe Source without opening when possible. Returns -1 if size cannot be determined.
func SizeFromStreamList ¶
SizeFromStreamList sums sizes for known sources. Returns -1 if any size cannot be determined.
func WithMaxPreallocate ¶
func WithMaxPreallocate(bytes int64) maxPreallocateOption
WithMaxPreallocate caps memory pre-allocation when sizeHint is provided. Set to 0 to disable the cap.
func WithMmap ¶
func WithMmap(enabled bool) mmapOption
WithMmap enables or disables mmap for file-to-memory fast paths.
func WithSpillThreshold ¶
func WithSpillThreshold(bytes int64) spillThresholdOption
WithSpillThreshold forces Memory to spill to File when sizeHint >= bytes. Set to 0 to disable spill-to-file behavior.
func WithThreshold ¶
func WithThreshold(bytes int64) thresholdOption
WithThreshold sets session auto file threshold (bytes). 0 = disabled.
Types ¶
type DownloadReaderCloser ¶
DownloadReaderCloser is a convenience interface for a read-only stream that also supports Close.
func NewDownloadReaderCloser ¶
func NewDownloadReaderCloser(src Source, cleanup ...func()) (DownloadReaderCloser, error)
NewDownloadReaderCloser wraps a Source as a DownloadReaderCloser.
type InOption ¶
type InOption func(*inConfig)
func DeleteAfterUse ¶
func DeleteAfterUse() InOption
DeleteAfterUse deletes local temp files for file/stream sources after read.
type Input ¶
type Input struct {
Reader io.ReadCloser
Size int64
Kind string
Path string
// contains filtered or unexported fields
}
Input represents an opened input source with metadata. Supports reusable reset (optional).
func OpenIn ¶
OpenIn opens a type-safe Source and returns an Input. If Reusable() is set, it will buffer (non-file) into memory or use ReaderAt for files.
func (*Input) IsReusable ¶
type IoManager ¶
func NewIoManager ¶
func NewIoManager(baseDir string, storageType StorageType, opts ...ManagerOption) (IoManager, error)
type IoSession ¶
type ManagerOption ¶
type ManagerOption interface {
// contains filtered or unexported methods
}
type ManagerOptionFunc ¶
type ManagerOptionFunc func(*managerConfig)
type OutConfig ¶
type OutConfig struct {
// contains filtered or unexported fields
}
func (OutConfig) AutoThreshold ¶
func (OutConfig) StorageTypeVal ¶
func (o OutConfig) StorageTypeVal() *StorageType
type OutHandle ¶
type OutHandle struct {
Writer io.WriteCloser
// contains filtered or unexported fields
}
type OutOption ¶
type OutOption interface {
// contains filtered or unexported methods
}
func OutReuse ¶
func OutReuse(outPtr **Output, opts ...OutReuseOpt) OutOption
OutReuse configures output reuse for OutScope.NewOut.
func WithStorage ¶
func WithStorage(st StorageType) OutOption
type OutOptionFunc ¶
type OutOptionFunc func(*OutConfig)
type OutReuseOpt ¶
type OutReuseOpt interface {
// contains filtered or unexported methods
}
func WithCleanupOld ¶
func WithCleanupOld(v bool) OutReuseOpt
func WithKeepMemCap ¶
func WithKeepMemCap(v bool) OutReuseOpt
func WithMaxMemCap ¶
func WithMaxMemCap(bytes int64) OutReuseOpt
type OutReuseOptFunc ¶
type OutReuseOptFunc func(*outReuseConfig)
type OutScope ¶
type OutScope struct {
Scope
// contains filtered or unexported fields
}
func (*OutScope) UseReaderAt ¶
UseReaderAt opens a Source as ReaderAt and records size for output decisions.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
func DoOut ¶
func DoOut(ctx context.Context, outCfg OutConfig, fn func(ctx context.Context, s *OutScope, w io.Writer) error) (*Output, error)
DoOut: returns *Output only (output-capable scope)
func DoOutResult ¶
func DoOutResult[T any](ctx context.Context, outCfg OutConfig, fn func(ctx context.Context, s *OutScope, w io.Writer) (*T, error)) (*Output, *T, error)
DoOutResult: returns *Output + *T (output-capable scope)
func ProcessAtResult ¶
func ProcessList ¶
func ProcessListResult ¶
func ProcessResult ¶
func (*Output) OpenReader ¶
func (o *Output) OpenReader() (io.ReadCloser, error)
func (*Output) OpenWriter ¶
func (o *Output) OpenWriter(sizeHint ...int64) (io.WriteCloser, error)
func (*Output) StorageType ¶
func (o *Output) StorageType() StorageType
type ReaderAtResult ¶
type ReaderAtResult struct {
// contains filtered or unexported fields
}
func ToReaderAt ¶
func ToReaderAt(ctx context.Context, r io.Reader, opts ...ToReaderAtOption) (*ReaderAtResult, error)
ToReaderAt converts any io.Reader into something that supports io.ReaderAt. - If the input already supports ReaderAt → returns it directly. - If it is small enough → keeps it in memory. - If too large → spills to temporary file.
func (*ReaderAtResult) Cleanup ¶
func (r *ReaderAtResult) Cleanup() error
func (*ReaderAtResult) ReaderAt ¶
func (r *ReaderAtResult) ReaderAt() io.ReaderAt
func (*ReaderAtResult) Size ¶
func (r *ReaderAtResult) Size() int64
func (*ReaderAtResult) Source ¶
func (r *ReaderAtResult) Source() string
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
func (*Scope) UseReaderAt ¶
UseReaderAt returns ReaderAt + size with options. Buffers into memory or spills to temp file based on options.
type Source ¶
type Source interface {
// contains filtered or unexported methods
}
Source is a type-safe input source.
func BytesSource ¶
func FileSource ¶
func InputSource ¶
func MultipartSource ¶
func MultipartSource(fh *multipart.FileHeader) Source
func OutputSource ¶
func ReadCloserSource ¶
func ReadCloserSource(rc io.ReadCloser) Source
func ReaderSource ¶
type StorageType ¶
type StorageType int
const ( File StorageType = iota Memory )
func (StorageType) String ¶
func (s StorageType) String() string
type ToReaderAtOption ¶
type ToReaderAtOption func(*ToReaderAtOptions)
func WithMaxMemoryBytes ¶
func WithMaxMemoryBytes(n int64) ToReaderAtOption
func WithTempDir ¶
func WithTempDir(dir string) ToReaderAtOption
func WithTempPattern ¶
func WithTempPattern(p string) ToReaderAtOption
type ToReaderAtOptions ¶
type ToReaderAtOptions struct {
// contains filtered or unexported fields
}