Documentation
¶
Index ¶
- func Copy(src Reader, dst Writer) (int64, error)
- func CopyStream(src StreamReader, dst StreamWriter) (int64, error)
- func GenerateFileName(fileName string) string
- func NewBytesStreamWriter() *bytesStreamWriter
- func Reset(rs Reader) error
- func WithTemp(fileExtension string, fn func(*TempFile) error) (err error)
- type DownloadReaderCloser
- type FileInfo
- type IOManager
- type Output
- func (o *Output) AsStreamReader() StreamReader
- func (o *Output) Bytes() ([]byte, error)
- func (o *Output) Cleanup() error
- func (o *Output) Clone() (*Output, error)
- func (o *Output) CopyTo(dst StreamWriter) (int64, error)
- func (o *Output) IsFile() bool
- func (o *Output) IsInMemory() bool
- func (o *Output) Keep() *Output
- func (o *Output) Path() (string, error)
- func (o *Output) Reader() (io.ReadCloser, error)
- func (o *Output) SaveAs(path string) error
- func (o *Output) Size() (int64, error)
- func (o *Output) WriteTo(w io.Writer) (int64, error)
- type OutputType
- type Reader
- type Session
- type SessionOption
- type StreamReader
- type StreamWriter
- type TempFile
- func (t *TempFile) AsOutStream() StreamWriter
- func (t *TempFile) AsStreamReader() StreamReader
- func (t *TempFile) AsStreamWriter() StreamWriter
- func (t *TempFile) Cleanup() error
- func (t *TempFile) Close() error
- func (t *TempFile) Create() (Writer, error)
- func (t *TempFile) Exists() bool
- func (t *TempFile) Meta() FileInfo
- func (t *TempFile) Open() (Reader, error)
- func (t *TempFile) Read(p []byte) (int, error)
- func (t *TempFile) Seek(offset int64, whence int) (int64, error)
- func (t *TempFile) Size() int64
- func (t *TempFile) Write(p []byte) (int, error)
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyStream ¶
func CopyStream(src StreamReader, dst StreamWriter) (int64, error)
---------- adapters & utilities ----------
func GenerateFileName ¶
func NewBytesStreamWriter ¶
func NewBytesStreamWriter() *bytesStreamWriter
NewBytesStreamWriter creates a StreamWriter that writes data into memory. Use Bytes() to retrieve the final in-memory result.
Types ¶
type DownloadReaderCloser ¶
func NewDownloadReaderCloser ¶
func NewDownloadReaderCloser(streamReader StreamReader, cleanup ...func()) (DownloadReaderCloser, error)
type IOManager ¶
type IOManager interface {
NewSession(id string, opts ...SessionOption) Session
Release() error // cleanup the entire baseDir
}
IOManager is the root manager for all temp files.
func NewIOManager ¶
NewIOManager creates a base temp directory for the whole process.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
func (*Output) AsStreamReader ¶
func (o *Output) AsStreamReader() StreamReader
func (*Output) Clone ¶
Clone creates a copy of this output. For file-based outputs, creates a new temp file.
func (*Output) CopyTo ¶
func (o *Output) CopyTo(dst StreamWriter) (int64, error)
CopyTo copies the output to a destination StreamWriter.
func (*Output) IsInMemory ¶
IsInMemory reports whether this output is stored in memory.
type OutputType ¶
type OutputType string
OutputType controls how session outputs are written.
const ( // OutputTempFile stores results on disk (default). OutputTempFile OutputType = "tempfile" // OutputBytes keeps results in memory using a bytes buffer. OutputBytes OutputType = "bytes" )
type Session ¶
type Session interface {
Do(ctx context.Context, outputExt string, fn func(ctx context.Context, w StreamWriter) error, opts ...SessionOption) (*Output, error)
Release() error
}
Session represents one request/job scope and has its own subdirectory for temp files.
type SessionOption ¶
type SessionOption struct {
WriterType OutputType
}
SessionOption customizes the behavior of Session instances.
type StreamReader ¶
StreamReader is a high-level abstraction for any data source that can be opened as a Reader (e.g. bytes, files, multipart uploads).
func NewBytesStreamReader ¶
func NewBytesStreamReader(name string, data []byte) StreamReader
NewBytesStreamReader creates a StreamReader from a byte slice.
func NewFileStreamReader ¶
func NewFileStreamReader(path string) (StreamReader, error)
NewFileStreamReader creates a StreamReader from a file path on disk.
func NewMultipartStreamReader ¶
func NewMultipartStreamReader(h *multipart.FileHeader) StreamReader
NewMultipartStreamReader creates a StreamReader from a multipart.FileHeader (e.g. Fiber upload).
type StreamWriter ¶
StreamWriter is a high-level abstraction for any destination that can create a Writer for writing data (e.g. files, buffers, temp files).
func NewFileStreamWriter ¶
func NewFileStreamWriter(path string) StreamWriter
NewFileStreamWriter creates a StreamWriter that writes data to a file path on disk.
type TempFile ¶
type TempFile struct {
Path string // path of the temp file on disk
// contains filtered or unexported fields
}
TempFile - Used for temp-file backed I/O - Focus: rely on disk instead of RAM, auto cleanup, share a single handle compatible with Output.Bytes()
func NewTempFile ¶
NewTempFile creates a temp file with a random name.
func NewTempFileInDir ¶
NewTempFileInDir creates a temp file inside the provided directory.
func NewTempFileWithName ¶
NewTempFileWithName creates a temp file using prefix + filename.
func (*TempFile) AsOutStream ¶
func (t *TempFile) AsOutStream() StreamWriter
AsOutStream kept for legacy naming (alias of AsStreamWriter).
func (*TempFile) AsStreamReader ¶
func (t *TempFile) AsStreamReader() StreamReader
AsStreamReader exposes TempFile as a StreamReader.
func (*TempFile) AsStreamWriter ¶
func (t *TempFile) AsStreamWriter() StreamWriter
AsStreamWriter exposes TempFile as a StreamWriter.
func (*TempFile) Create ¶
Create exposes TempFile as a StreamWriter. Always prepare a blank file before writing.
func (*TempFile) Open ¶
Open exposes TempFile as a StreamReader. Returns a Reader that supports Seek and Close.
