scan

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package scan provides concurrent filesystem scanning code

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(c io.Closer)

Close wraps io.Closer Close func with error handling

func Scan

func Scan(path string, fs Filesystem, handlers ...Handler)

Scan do specified path scanning and executes folder handler on each folder and all file handlers on each file

Example
package main

import "fmt"

type hndl struct{}

func (*hndl) Handle(*Event) { fmt.Println("from Handle") }

func main() {
	fs := NewOsFs()

	Scan("/somepath", fs, &hndl{})
}
Output:

Types

type Event added in v0.12.0

type Event struct {
	// File set not nil in case of file event occurred
	File *FileEntry

	// Folder set not nil in case of folder event occurred
	Folder *FolderEntry
}

Event defines scanning event structure that can contain file or folder event information. Each event can only be file or folder event but not file and folder simultaneously. Why do not make unified event type with three fields where count field in case of file will always be one? The answer is - memory. Typically there are much more files then folders in the filesystem so we can decrease memory consumption not to have extra 4 bytes for each file event because we know they are always contain one

type File added in v0.10.10

type File interface {
	io.Closer

	// Readdir reads the contents of the directory associated with file and
	// returns a slice of up to n FileInfo values, as would be returned
	// by Lstat, in directory order. Subsequent calls on the same file will yield
	// further FileInfos.
	// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
	// Readdir returns an empty slice, it will return a non-nil error
	// explaining why. At the end of a directory, the error is io.EOF.
	//
	// If n <= 0, Readdir returns all the FileInfo from the directory in
	// a single slice. In this case, if Readdir succeeds (reads all
	// the way to the end of the directory), it returns the slice and a
	// nil error. If it encounters an error before the end of the
	// directory, Readdir returns the FileInfo read until that point
	// and a non-nil error.
	Readdir(count int) ([]os.FileInfo, error)
}

File represents an open file descriptor.

type FileEntry

type FileEntry struct {
	// File size in bytes
	Size int64

	// Full path
	Path string
}

FileEntry represent file description

type Filesystem added in v0.10.10

type Filesystem interface {
	// Open opens file for reading
	Open(name string) (File, error)
}

Filesystem represents filesystem abstraction

func NewOsFs added in v0.12.0

func NewOsFs() Filesystem

NewOsFs creates new real os backed Filesystem instance

type FolderEntry

type FolderEntry struct {
	FileEntry

	// The number of files in a folder
	Count int64
}

FolderEntry represent folder description

type Handler

type Handler interface {
	// Handle handles filesystem event
	Handle(evt *Event)
}

Handler defines scanning handler interface that handles filesystem events

Jump to

Keyboard shortcuts

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