handlers

package
v3.53.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

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

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 context.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(ctx context.Context, reader io.Reader) (io.Reader, bool)

IsFiletype returns true if the provided reader is an archive.

func (*Archive) New

func (a *Archive) New()

New sets a default maximum size and current size counter.

func (*Archive) ReadToMax

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

ReadToMax reads up to the max size.

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.

Jump to

Keyboard shortcuts

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