utils

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Inch2MM    = 25.4
	Inch2Point = 72.0
	MM2Point   = Inch2Point / Inch2MM
	Point2MM   = Inch2MM / Inch2Point
)

Variables

View Source
var FileHashSize = 10

FileHashSize is the maximum number of hexidecimal digits returned for file hashes.

Functions

func ChangePathDir

func ChangePathDir(inDir, inPath, outDir string) (string, error)

ChangePathDir returns `inPath` with its ancestor directory `inDir` replaced with `outDir`.

func ChangePathDirExt

func ChangePathDirExt(inDir, inPath, outDir, outExt string) (string, error)

ChangePathDir returns `inPath` with its ancestor directory `inDir` replaced with `outDir` and its extension replaced with `outExt`.

func ChangePathExt

func ChangePathExt(inPath, outExt string) string

ChangePathExt returns `inPath` with its extension replaced with `outExt`.

func Compress

func Compress(data []byte) ([]byte, error)

Compress returns flate compressed `data`.

func CompressInPlace

func CompressInPlace(data *[]byte) error

CompressInPlace replaces `data` with its flate compressed image on success. On failure `data` is not changed.

func CopyFile

func CopyFile(src, dest string) error

func Decompress

func Decompress(data []byte) ([]byte, error)

Decompress returns the raw data of flate compressed `data`.

func DecompressInPlace

func DecompressInPlace(data *[]byte) error

CompressInPlace replaces the flate compressed `data` with its raw data on success. On failure `data` is not changed.

func Exists

func Exists(filename string) bool

Exists returns true if `filename` exists.

func FileHash

func FileHash(filename string) (string, error)

FileHash returns a hex encoded string of the SHA-256 digest of the contents of file `filename`.

func FileSize

func FileSize(filename string) (int64, error)

FileSize returns the size of file `filename` in bytes.

func IntRange

func IntRange(i0, i1 int) []int

IntRange returns slice [i0, i1).

func IntSetIntersection

func IntSetIntersection(a, b map[int]bool) map[int]bool

IntSetIntersection returns `a` ∩ `b`.

func IntSetToSlice

func IntSetToSlice(set map[int]bool) []int

IntSetToSlice returns keys of `set` as a slice.

func IntSetUnion

func IntSetUnion(a, b map[int]bool) map[int]bool

IntSetUnion returns `a` ∪ `b`.

func IntSliceDifference

func IntSliceDifference(a, b []int) []int

IntSliceDifference returns the elements in `a` that aren't in `b`.

func IntSliceIntersection

func IntSliceIntersection(a, b []int) []int

IntSliceIntersection returns `a` ∩ `b`.

func IntSliceSymmetricDifference

func IntSliceSymmetricDifference(a, b []int) []int

IntSliceDifference returns the elements in `a` that aren't in `b` plus the elements in `b` that aren't in `a`.

func IntSliceToSet

func IntSliceToSet(arr []int) map[int]bool

IntSliceToSet returns a map whose keys are the elements of `arr`.

func IntSliceUnion

func IntSliceUnion(a, b []int) []int

IntSliceUnion returns `a` ∪ `b`.

func MMToPoint

func MMToPoint(x float64) float64

func MinMaxIntSlice

func MinMaxIntSlice(arr []int) (min, max int, valid bool)

MinMaxIntSlice returns min and max of `arr`. `valid` is true if `arr` contains values.

func MkDir

func MkDir(dir string) error

MkDir creates a directory called `dir` if it doesn't already exist.

func MkParentDir

func MkParentDir(filename string) error

MkParentDir creates the parent directory for `filename` if it doesn't already exist.

func PointToMM

func PointToMM(x float64) float64

func ReaderSizeHash

func ReaderSizeHash(rs io.ReadSeeker) (int64, string, error)

ReaderSizeHash return the size in bytes and the hash of the file referenced by `rs`. The hash is hex encoded string of the SHA-256 digest of the contents of `rs`.

func RegularFile

func RegularFile(filename string) (bool, error)

RegularFile returns true if file `filename` is a regular file.

func RemoveDirectory

func RemoveDirectory(dir string) error

RemoveDirectory recursively removes directory `dir` and its contents from disk.

func StringUniques

func StringUniques(arr []string) []string

StringUniques returns the unique strings in `arr`.

func WriteJsonSlice

func WriteJsonSlice(filename string, vals []string) error

WriteJsonSlice writes slice `vals` to json file `filename`, one line per string. NOTE: We write this json file in a human readable way because we will be using it in development

Types

This section is empty.

Jump to

Keyboard shortcuts

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