Documentation ¶
Index ¶
- Variables
- func HandleFile(ctx logContext.Context, reader io.Reader, chunkSkel *sources.Chunk, ...) error
- func SetArchiveMaxDepth(depth int)
- func SetArchiveMaxSize(size int)
- func SetArchiveMaxTimeout(timeout time.Duration)
- func WithSkipArchives(skip bool) func(*fileHandlingConfig)
- type DataOrErr
- type FileHandler
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyReader = errors.New("reader is empty") // ErrProcessingFatal indicates a severe error that requires stopping the file processing. ErrProcessingFatal = errors.New("fatal error processing file") // ErrProcessingWarning indicates a recoverable error that can be logged, // allowing processing to continue. ErrProcessingWarning = errors.New("error processing file") )
var ErrMaxDepthReached = errors.New("max archive depth reached")
Functions ¶
func HandleFile ¶
func HandleFile( ctx logContext.Context, reader io.Reader, chunkSkel *sources.Chunk, reporter sources.ChunkReporter, options ...func(*fileHandlingConfig), ) error
HandleFile orchestrates the complete file handling process for a given file. It determines the MIME type of the file, selects the appropriate handler based on this type, and processes the file. This function initializes the handling process and delegates to the specific handler to manage file extraction or processing.
The function will return nil (success) in the following cases: - If the reader is empty (ErrEmptyReader) - If skipArchives option is true and the file is detected as an archive - If all chunks are processed successfully without critical errors
The function will return an error in the following cases: - If the reader is nil - If there's an error creating the file reader - If there's an error closing the reader - If a critical error occurs during chunk processing (context cancellation, deadline exceeded, or ErrProcessingFatal) - If there's an error reporting a chunk
Non-critical errors during chunk processing are logged but do not cause the function to return an error.
func SetArchiveMaxDepth ¶ added in v3.27.0
func SetArchiveMaxDepth(depth int)
SetArchiveMaxDepth sets the maximum depth of the archive.
func SetArchiveMaxSize ¶ added in v3.27.0
func SetArchiveMaxSize(size int)
SetArchiveMaxSize sets the maximum size of the archive.
func SetArchiveMaxTimeout ¶ added in v3.27.0
SetArchiveMaxTimeout sets the maximum timeout for the archive handler.
func WithSkipArchives ¶ added in v3.63.7
func WithSkipArchives(skip bool) func(*fileHandlingConfig)
WithSkipArchives sets the skipArchives field of the fileHandlingConfig. If skip is true, the FileHandler will skip archive files.
Types ¶
type DataOrErr ¶ added in v3.84.0
DataOrErr represents a result that can either contain data or an error. The Data field holds the byte slice of data, and the Err field holds any error that occurred. This structure is used to handle asynchronous file processing where each chunk of data or potential error needs to be communicated back to the caller. It allows for efficient streaming of file contents while also providing a way to propagate errors that may occur during the file handling process.
type FileHandler ¶ added in v3.76.0
type FileHandler interface {
HandleFile(ctx logContext.Context, reader fileReader) chan DataOrErr
}
FileHandler represents a handler for files. It has a single method, HandleFile, which takes a context and a fileReader as input, and returns a channel of byte slices and an error.