Documentation ¶
Index ¶
- func HandleFile(ctx context.Context, file io.Reader, chunkSkel *sources.Chunk, ...) bool
- func SetArchiveMaxDepth(depth int)
- func SetArchiveMaxSize(size int)
- func SetArchiveMaxTimeout(timeout time.Duration)
- type Archive
- func (a *Archive) FromFile(originalCtx context.Context, data io.Reader) chan []byte
- func (a *Archive) HandleSpecialized(ctx logContext.Context, reader io.Reader) (io.Reader, bool, error)
- func (a *Archive) IsFiletype(ctx context.Context, reader io.Reader) (io.Reader, bool)
- func (a *Archive) New()
- func (a *Archive) ReadToMax(ctx context.Context, reader io.Reader) (data []byte, err error)
- type Handler
- type SpecializedHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleFile ¶
func HandleFile(ctx context.Context, file io.Reader, chunkSkel *sources.Chunk, chunksChan chan *sources.Chunk) bool
HandleFile processes a given file by selecting an appropriate handler from DefaultHandlers. It first checks if the handler implements SpecializedHandler for any special processing, then falls back to regular file type handling. If successful, it reads the file in chunks, packages them in the provided chunk skeleton, and sends them to chunksChan. The function returns true if processing was successful and false otherwise. Context is used for cancellation, and the caller is responsible for canceling it if needed.
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.
Types ¶
type Archive ¶
type Archive struct {
// contains filtered or unexported fields
}
Archive is a handler for extracting and decompressing archives.
func (*Archive) HandleSpecialized ¶ added in v3.49.0
func (a *Archive) HandleSpecialized(ctx logContext.Context, reader io.Reader) (io.Reader, bool, error)
HandleSpecialized takes a file path and an io.Reader representing the input file, and processes it based on its extension, such as handling Debian (.deb) and RPM (.rpm) packages. It returns an io.Reader that can be used to read the processed content of the file, and an error if any issues occurred during processing. If the file is specialized, the returned boolean is true with no error. The caller is responsible for closing the returned reader.
func (*Archive) IsFiletype ¶
IsFiletype returns true if the provided reader is an archive.
type Handler ¶
type Handler interface { FromFile(context.Context, io.Reader) chan []byte IsFiletype(context.Context, io.Reader) (io.Reader, bool) New() }
func DefaultHandlers ¶
func DefaultHandlers() []Handler
type SpecializedHandler ¶ added in v3.49.0
type SpecializedHandler interface { // HandleSpecialized examines the provided file reader within the context and determines if it is a specialized archive. // It returns a reader with any necessary modifications, a boolean indicating if the file was specialized, // and an error if something went wrong during processing. HandleSpecialized(logContext.Context, io.Reader) (io.Reader, bool, error) }
SpecializedHandler defines the interface for handlers that can process specialized archives. It includes a method to handle specialized archives and determine if the file is of a special type.