fileio

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package fileio provides functionality to interact with the OSs filesystem. This includes iteration over (parts of) the filesystem, as well as enumeration of network shares.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDriveType = fmt.Errorf("not a valid DriveType, try [%s]", strings.Join(_DriveTypeNames, ", "))
View Source
var ErrSkipped = fmt.Errorf("skipped")
View Source
var (
	// FilesBuffer sets how many files can be buffered at one time
	// during iteration.
	FilesBuffer = 8
)

Functions

func ComputeHashes added in v0.8.0

func ComputeHashes(file string) (md5sum, sha256sum string, err error)

ComputeHashes computes the md5 and sha256 hashes of a given file.

func DriveTypeNames

func DriveTypeNames() []string

DriveTypeNames returns a list of possible string values of DriveType.

func Enumerate

func Enumerate(typeMask DriveType) ([]string, error)

Enumerate enumerates all mounted drives of the given type.

Types

type CachingHasher added in v0.8.0

type CachingHasher struct {
	// contains filtered or unexported fields
}

func NewCachingHasher added in v0.8.0

func NewCachingHasher() *CachingHasher

func (*CachingHasher) ComputeHashes added in v0.8.0

func (h *CachingHasher) ComputeHashes(file string) (md5sum, sha256sum string, err error)

ComputeHashes computes the md5 and sha256 hashes of a given file.

type DriveType

type DriveType int

DriveType describes the type of a system drive.

ENUM( Unknown=0 Removable=1 Fixed=2 Remote=4 CDRom=8 RAM=16 )

const (
	// DriveTypeUnknown is a DriveType of type Unknown.
	DriveTypeUnknown DriveType = iota
	// DriveTypeRemovable is a DriveType of type Removable.
	DriveTypeRemovable
	// DriveTypeFixed is a DriveType of type Fixed.
	DriveTypeFixed
	// DriveTypeRemote is a DriveType of type Remote.
	DriveTypeRemote DriveType = iota + 1
	// DriveTypeCDRom is a DriveType of type CDRom.
	DriveTypeCDRom DriveType = iota + 4
	// DriveTypeRAM is a DriveType of type RAM.
	DriveTypeRAM DriveType = iota + 11
)

func ParseDriveType

func ParseDriveType(name string) (DriveType, error)

ParseDriveType attempts to convert a string to a DriveType.

func (DriveType) MarshalText

func (x DriveType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (DriveType) String

func (x DriveType) String() string

String implements the Stringer interface.

func (*DriveType) UnmarshalText

func (x *DriveType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type FSScanProgress

type FSScanProgress struct {
	File    File
	Matches []yara.MatchRule
	Error   error
}

FSScanProgress provides information about the scanning progress.

type FSScanner

type FSScanner struct {
	NGoroutines int
	// contains filtered or unexported fields
}

FSScanner is a scanner for the filesystem.

func NewFSScanner

func NewFSScanner(scanner FileScanner) *FSScanner

NewFSScanner create a new FSScanner, which will use the given FileScanner to scan any encountered file.

func (*FSScanner) Scan

func (s *FSScanner) Scan(it Iterator) (<-chan *FSScanProgress, error)

Scan scans all files, emitted by the given Iterator.

type File

type File interface {
	Path() string
	Stat() (os.FileInfo, error)
	Hashes() (md5sum, sha256sum string, err error)
	Inode() uint64
	Device() uint64
	Offset() uint64
	EnableHashMarshalling() error
}

File is a small abstraction layer for a file.

func CloneFile added in v0.8.0

func CloneFile(f File) File

func NewFile added in v0.8.0

func NewFile(path string) File

func NewFileWithInode added in v0.17.0

func NewFileWithInode(path string, inode uint64, device uint64, offset uint64) File

type FileScanner

type FileScanner interface {
	ScanFile(filename string) (results []yara.MatchRule, err error)
}

FileScanner provides functionality to scan files.

type Iterator

type Iterator interface {
	Next() (File, error)
	Close() error
}

Iterator provides capability to iterate over files.

func Concat

func Concat(iterators ...Iterator) Iterator

Concat concatenates multiple Iterators. When one Iterator is exhausted, the next one is used.

func Concurrent

func Concurrent(iterators ...Iterator) Iterator

Concurrent combines the given Iterators concurrently. Each given Iterator will run in its own goroutine.

func IterateFileList added in v0.9.0

func IterateFileList(files []string) Iterator

IterateFileList starts an asynchronous, Iterator over the given files.

func IteratePath

func IteratePath(ctx context.Context, path string, validExtensions []string) (Iterator, error)

IteratePath starts an asynchronous, recursive Iterator over all files and subdirectores in the given path. For each file with one of the given validExtensions, a File will be emitted, which can be read using Iterator.Next.

type OSFile added in v0.8.0

type OSFile struct {
	FilePath  string `json:"path"`
	MD5Sum    string `json:"md5,omitempty"`
	SHA256Sum string `json:"sha256,omitempty"`
	// contains filtered or unexported fields
}

func (*OSFile) Device added in v0.17.0

func (f *OSFile) Device() uint64

Device returns the ID of the device containing the file.

func (*OSFile) EnableHashMarshalling added in v0.8.0

func (f *OSFile) EnableHashMarshalling() (err error)

EnableHashMarshalling computes the hashes and stores them for later marshalling.

func (*OSFile) Hashes added in v0.8.0

func (f *OSFile) Hashes() (md5sum, sha256sum string, err error)

Hashes returns the computed hashes of the file.

func (*OSFile) Inode added in v0.17.0

func (f *OSFile) Inode() uint64

Inode returns the inode number associated with the file.

func (*OSFile) Offset added in v0.17.0

func (f *OSFile) Offset() uint64

Offset returns the offset in bytes into the file.

func (*OSFile) Path added in v0.8.0

func (f *OSFile) Path() string

Path returns the path of the file.

func (*OSFile) Stat added in v0.8.0

func (f *OSFile) Stat() (os.FileInfo, error)

Stat returns the os.FileInfo associated with the file.

Jump to

Keyboard shortcuts

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