filebox

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 21 Imported by: 6

README

filebox

a simple file dev tool pkg, supported features as follows:

  • compress, uncompress
  • crc sum
  • hash sum
  • files, dir copy
  • file helper

install

go get -u github.com/dstgo/filebox@latest

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IEEE32       Crc32 = crc32I{_IEEE32}
	Castagnoli32 Crc32 = crc32I{_Castagnoli32}
	Koopman32    Crc32 = crc32I{_Koopman32}

	ISO64  Crc64 = crc64I{_ISO64}
	ECMA64 Crc64 = crc64I{_ECMA64}
)

Functions

func BinaryPath added in v1.1.0

func BinaryPath() string

BinaryPath returns the current binary running path

func BytesToString added in v1.1.0

func BytesToString(bytes []byte) string

BytesToString return the string representation of the bytes, if the bytes changes, string changes too

func CallerPath added in v1.1.0

func CallerPath() string

CallerPath returns the caller file path

func Copy added in v1.1.0

func Copy(src, dst string) error

Copy copies src to dest path, only copy dir and regular files.

func CopyFs added in v1.1.0

func CopyFs(srcFs fs.FS, srcpath, destpath string) error

CopyFs copies the specified srcpath from srcFs to destpath in os fs, only copy dir and regular files.

func CreateFile

func CreateFile(filename string) (*os.File, error)

CreateFile creates a new file, create parent-directory first if parent-directory does not exist, then create the specified file.

func FileSum added in v1.0.1

func FileSum(name string, h hash.Hash) []byte

func IsDir added in v1.0.1

func IsDir(name string) bool

IsDir checks if the given path is a directory

func IsExist

func IsExist(name string) bool

IsExist checks if the given path exists

func Md5 added in v1.0.1

func Md5(name string) []byte

func Mkdir

func Mkdir(dir string) error

Mkdir creates a directory, create parent-directory first if parent-directory does not exist.

func OpenFile

func OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error)

OpenFile open a new file, create parent-directory first if parent-directory does not exist, then open the specified file.

func ReadLine added in v1.1.0

func ReadLine(file string) (next func() ([]byte, error), cleanup func() error, err error)

ReadLine returns an iterator that iterate over per line of the given file.

func ReadLines added in v1.1.0

func ReadLines(file string) ([][]byte, error)

ReadLines returns a slice of bytes of file contents split by line.

func ReadStringLines added in v1.1.0

func ReadStringLines(filename string) ([]string, error)

ReadStringLines return a slice of strings of file contents split by line.

func ReaderSum added in v1.1.0

func ReaderSum(reader io.Reader, h hash.Hash) []byte

func Sha1 added in v1.0.1

func Sha1(name string) []byte

func Sha256 added in v1.0.1

func Sha256(name string) []byte

func Sha512 added in v1.0.1

func Sha512(name string) []byte

func StringToBytes added in v1.1.0

func StringToBytes(str string) []byte

StringToBytes return the underlying []byte of string, returned bytes must not be modified

func TarGzip

func TarGzip(src, dest string) error

TarGzip use tar gzip to compress src path into an archive, only includes dir and regular files.

func TempDir added in v1.1.0

func TempDir(dir string) (temp string, cleanup func() error, err error)

TempDir creates a temporary directory, and returns a cleanup function to clean up temporary dir

func TempFile added in v1.1.0

func TempFile(dir, pattern string) (temp *os.File, cleanup func() error, err error)

TempFile creates a temporary file, and returns a cleanup function to clean up temporary file

func Truncate added in v1.1.0

func Truncate(filename string) error

Truncate truncates the specified file

func UnTarGzip

func UnTarGzip(src, dest string) error

UnTarGzip use tar gzip to decompress src archive into the destination path.

func UnZip added in v1.1.0

func UnZip(src string, dest string) error

UnZip use zip to decompress src archive into destination path.

func Zip

func Zip(src string, dest string) error

Zip use zip to compress src path into an archive, only includes dir and regular files

Types

type Crc32 added in v1.1.0

type Crc32 interface {
	Sum(data []byte) uint32
	Update(crc uint32, data []byte) uint32
}

Crc32 generate 32-bit CRC sum

type Crc64 added in v1.1.0

type Crc64 interface {
	Sum(data []byte) uint64
	Update(crc uint64, data []byte) uint64
}

Crc64 generate 64-bit CRC sum

Jump to

Keyboard shortcuts

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