handlers

package
v3.67.5 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleFile

func HandleFile(ctx logContext.Context, reReader *diskbufferreader.DiskBufferReader, chunkSkel *sources.Chunk, reporter sources.ChunkReporter, opts ...Option) 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 reports them to the chunk reporter. 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

func SetArchiveMaxTimeout(timeout time.Duration)

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) FromFile

func (a *Archive) FromFile(originalCtx logContext.Context, data io.Reader) chan []byte

FromFile extracts the files from an archive.

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

func (a *Archive) IsFiletype(_ logContext.Context, reader io.Reader) (io.Reader, bool)

IsFiletype returns true if the provided reader is an archive.

func (*Archive) New

func (a *Archive) New(opts ...Option)

New creates a new Archive handler with the provided options.

func (*Archive) ReadToMax

func (a *Archive) ReadToMax(ctx logContext.Context, reader io.Reader) (data []byte, err error)

ReadToMax reads up to the max size.

type Handler

type Handler interface {
	FromFile(logContext.Context, io.Reader) chan []byte
	IsFiletype(logContext.Context, io.Reader) (io.Reader, bool)
	New(...Option)
}

func DefaultHandlers

func DefaultHandlers() []Handler

type Option added in v3.63.5

type Option func(Handler)

Option is a function type that applies a configuration to a Handler.

func WithSkipArchives added in v3.63.7

func WithSkipArchives(skip bool) Option

WithSkipArchives returns a Option that configures whether to skip archive files.

func WithSkipBinaries added in v3.63.5

func WithSkipBinaries(skip bool) Option

WithSkipBinaries returns a Option that configures whether to skip binary files.

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.

Jump to

Keyboard shortcuts

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