file

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToMB

func BytesToMB(bytes int64) float64

BytesToMB converts bytes to mega-bytes.

func DimToGigaPixel

func DimToGigaPixel(w, h int) float64

DimToGigaPixel computes the giga-pixel from width and height.

func EnsureDir

func EnsureDir(p string, perm os.FileMode) error

EnsureDir ensures a dir exists.

func Filesize

func Filesize(file string) (int64, error)

Filesize returns the filesize in bytes of a file.

func GetBase64String added in v1.1.1

func GetBase64String(f string) (string, error)

GetBase64String reads the file and return its bytes as base64 string.

func GetImageSize

func GetImageSize(img string) (int, int, error)

GetImageSize decodes the width and height of an image.

func GuessFileType

func GuessFileType(file string) (string, error)

GuessFileType guesses the type of file.

func IsFileExist

func IsFileExist(f string) bool

IsFileExist checks if file exists.

func IsImageFile

func IsImageFile(img string) (bool, error)

IsImageFile tells if the file is an image.

func IsZipFile

func IsZipFile(f string) (bool, error)

IsZipFile tells if the file is a zip file.

func MergeFile

func MergeFile(parts []string, output string) (int, error)

MergeFile merges file parts into one single binary. It returns the number of bytes written and an error, if any.

func ReadFile added in v1.1.0

func ReadFile(path string) ([]string, error)

ReadFile reads a text file from path.

func Sha1sum

func Sha1sum(file string) (string, error)

Sha1sum computes the sha1sum of the file.

func SplitFile

func SplitFile(file, outDir string, chunkSize int64, verbose bool) ([]string, error)

SplitFile splits the file into parts and put it in the outDir. Each part would have chunkSize number of bytes. If chunkSize is larger than filesize, do nothing. If chunkSize is non-positive, will reset to 100 MB. Return filenames of parts.

func WalkFiles

func WalkFiles(done <-chan struct{}, root string, skip string) (<-chan string, <-chan error)

WalkFiles starts a goroutine to walk the directory tree at root and send the path of each regular file on the string channel. It sends the result of the walk on the error channel. If done is closed, walkFiles abandons its work. skip is a regular expression pattern used for skipping paths. Would not skip if it is an empty string.

Types

type ImageDigest

type ImageDigest struct {
	IsImage  bool
	Path     string
	URL      string // relative url from root
	Filename string
	Filetype string
	Filesize int64 // in bytes
	Width    int
	Height   int
	GP       float64
	SHA1     string
	Existed  bool // existed in altizure or not
	Error    error
}

ImageDigest is the product of reading a regular file in local file system.

type ImageDigester

type ImageDigester struct {
	Root      string
	PID       string
	LightWork bool
	Done      <-chan struct{}
	Paths     <-chan string
	Result    chan<- ImageDigest
}

ImageDigester reads path names from paths. If light work is set, only set `IsImage`, `Path`, `URL` and `Filename`.

func (*ImageDigester) Digest

func (id *ImageDigester) Digest()

Digest reads path names from Paths and sends digests of the corresponding files on Result until either Paths or Done is closed.

func (*ImageDigester) Run

func (id *ImageDigester) Run(n int) int

Run starts n number of goroutines to digest image files. If n is not positive, it will be set to number of CPU cores x 4. Return n.

Jump to

Keyboard shortcuts

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