Documentation ¶
Index ¶
- func BytesToMB(bytes int64) float64
- func DimToGigaPixel(w, h int) float64
- func EnsureDir(p string, perm os.FileMode) error
- func Filesize(file string) (int64, error)
- func GetBase64String(f string) (string, error)
- func GetImageSize(img string) (int, int, error)
- func GuessFileType(file string) (string, error)
- func IsFileExist(f string) bool
- func IsImageFile(img string) (bool, error)
- func IsZipFile(f string) (bool, error)
- func MergeFile(parts []string, output string) (int, error)
- func ReadFile(path string) ([]string, error)
- func Sha1sum(file string) (string, error)
- func SplitFile(file, outDir string, chunkSize int64, verbose bool) ([]string, error)
- func WalkFiles(done <-chan struct{}, root string, skip string) (<-chan string, <-chan error)
- type ImageDigest
- type ImageDigester
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DimToGigaPixel ¶
DimToGigaPixel computes the giga-pixel from width and height.
func GetBase64String ¶ added in v1.1.1
GetBase64String reads the file and return its bytes as base64 string.
func GetImageSize ¶
GetImageSize decodes the width and height of an image.
func GuessFileType ¶
GuessFileType guesses the type of file.
func IsImageFile ¶
IsImageFile tells if the file is an image.
func MergeFile ¶
MergeFile merges file parts into one single binary. It returns the number of bytes written and an error, if any.
func SplitFile ¶
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 ¶
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.