Documentation ¶
Index ¶
- Constants
- Variables
- func FixPath(path string) string
- func HashingKey(settings CipherSettings) []byte
- func TransformPack(data []byte, compression byte, encryption byte, key []byte) ([]byte, error)
- func TransformUnpack(data []byte, compression byte, encryption byte, key []byte) ([]byte, error)
- type BundleFile
- type BundleSettings
- type CipherSettings
- type FAT
- type FATItem
- type FinishResult
- type Footer
- type Header
- type ListResult
- type ListSettings
- type PackSettings
- func (this *PackSettings) Finish(err error, fileCount int64, size int64, dupCount int, dupSize int64) FinishResult
- func (this *PackSettings) FinishError(err error) FinishResult
- func (this *PackSettings) Progress(total, index int, filename string)
- func (this *PackSettings) ProgressError(err error, filename string)
- type ProgressState
- type UnpackSettings
- func (this *UnpackSettings) Finish(err error, fileCount int64, size int64, dupCount int, dupSize int64) FinishResult
- func (this *UnpackSettings) FinishError(err error) FinishResult
- func (this *UnpackSettings) Progress(total, index int, filename string)
- func (this *UnpackSettings) ProgressError(err error, filename string)
Constants ¶
const ( ENCRYPT_NONE = iota ENCRYPT_AES )
Encryption enum constants
const ( COMPRESS_NONE = iota COMPRESS_GZIP )
Compression enum constants
const DEFAULT_PERMISSION = 0755
const FOOTER_SIZE = 8 + 4 + MAGIC_SIZE
FOOTER_SIZE is the size of footer
const HEADER_SIZE = MAGIC_SIZE + 1 + 1 + 1 + 8 + 8
HEADER_SIZE is the size of the Header
const MAGIC_SIZE = 5
const MagicBytes = "IPACK"
Magic bytes to identify the file format
const VERSION_1 = 1
Variables ¶
var ByteOrder = binary.LittleEndian
Functions ¶
func FixPath ¶
Fixing filepath on Windows to support longer filepath than 255 bytes. More information: https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
func HashingKey ¶
func HashingKey(settings CipherSettings) []byte
HashingKey is hashing the key with CipherSettings values
func TransformPack ¶
TransformPack is transform the content of file to the package (encrypt, compress)
Types ¶
type BundleFile ¶
type BundleFile struct { Path string File *os.File FAT FAT Header *Header DataBaseOffset int64 Settings BundleSettings DupCount int DupSize int64 // contains filtered or unexported fields }
BundleFile contains all info from bundle
func CreateBundle ¶
func CreateBundle(filename string, settings BundleSettings) (*BundleFile, error)
CreateBundle created a new bundle file & struct.
func OpenBundle ¶
func OpenBundle(filename string, cipherKey []byte) (*BundleFile, error)
OpenBundle open an exist bundle file. Load header, footer and FAT
func (*BundleFile) AddFile ¶
func (this *BundleFile) AddFile(relativePath, file string) (*FATItem, error)
AddFile adds a file to the bundle file
func (*BundleFile) ReadFile ¶
func (this *BundleFile) ReadFile(item FATItem) ([]byte, error)
ReadFile reads the content of the file from the bundle
func (*BundleFile) ReadFileFromPath ¶
func (this *BundleFile) ReadFileFromPath(filepath string) ([]byte, error)
ReadFileFromPath searches the FATItem in FAT by `filepath“ and reads the content of the file from the bundle
type BundleSettings ¶
BundleSettings records the settings of the bundle file
type CipherSettings ¶
ChiperSettings records the settings of encryption/decryption
func NewCipherSettings ¶
func NewCipherSettings(key string) CipherSettings
NewCipherSettings created a new CipherSettings instance with default values
type FAT ¶
type FAT struct { Count int64 `json:"count"` Size int64 `json:"size"` Items []FATItem `json:"items"` }
FAT is a structure for File-Allocation-Table in package
func FATFromJSON ¶
FATFromJSON build FAT struct from JSON string
type FATItem ¶
type FATItem struct { Path string `json:"path"` Offset int64 `json:"offset"` Size int64 `json:"size"` OrigSize int64 `json:"origSize"` Hash [64]byte `json:"-"` MTime int64 `json:"mTime"` Mode uint32 `json:"mode"` Perm uint32 `json:"perm"` }
FATItem is a structure for file item in FAT
type FinishResult ¶
FinishResult records some information about packing or unpacking
func Pack ¶
func Pack(settings PackSettings) FinishResult
Pack bundles the files of the source directory to the target package file.
func Unpack ¶
func Unpack(settings UnpackSettings) FinishResult
Unpack extract files from the package file
type Footer ¶
type Footer struct {}
Footer is a struct for footer of package
type Header ¶
type Header struct { Magic []byte Version byte Encrypt byte Compress byte FatSize int64 Created int64 }
Header is the header of package
type ListResult ¶
ListResult records the result of the listing
func ListPack ¶
func ListPack(settings ListSettings) ListResult
ListPack lists the FAT from the package. Returns a ListResult instance with the FAT
type ListSettings ¶
type ListSettings struct { PackFileName string Cipher CipherSettings OnFinish chan ListResult }
ListSettings records settings of the listing
func (*ListSettings) Finish ¶
func (this *ListSettings) Finish(err error, fat *FAT) ListResult
Finish returns a success ListResult instance and put to the OnFinish channel if it's not nil
func (*ListSettings) FinishError ¶
func (this *ListSettings) FinishError(err error) ListResult
Finish returns an errored ListResult instance and put to the OnFinish channel if it's not nil
type PackSettings ¶
type PackSettings struct { SourceDir string TargetFilename string Includes string Excludes string Compression byte Encryption byte Cipher CipherSettings OnProgress chan ProgressState OnFinish chan FinishResult }
PackSettings records the settings of the packing
func (*PackSettings) Finish ¶
func (this *PackSettings) Finish(err error, fileCount int64, size int64, dupCount int, dupSize int64) FinishResult
Finish returns a success FinishResult instance and put to the OnFinish channel if it's not nil
func (*PackSettings) FinishError ¶
func (this *PackSettings) FinishError(err error) FinishResult
Finish returns an errored FinishResult instance and put to the OnFinish channel if it's not nil
func (*PackSettings) Progress ¶
func (this *PackSettings) Progress(total, index int, filename string)
Progress push a success ProgressState instance to the OnProgress channel.
func (*PackSettings) ProgressError ¶
func (this *PackSettings) ProgressError(err error, filename string)
ProgressError push an error ProgressState instance to the OnProgress channel.
type ProgressState ¶
ProgressState records the state of packing or unpacking
type UnpackSettings ¶
type UnpackSettings struct { PackFileName string TargetDir string Includes string Excludes string Cipher CipherSettings OnProgress chan ProgressState OnFinish chan FinishResult }
UnpackSettings records the settings of the unpacking
func (*UnpackSettings) Finish ¶
func (this *UnpackSettings) Finish(err error, fileCount int64, size int64, dupCount int, dupSize int64) FinishResult
Finish returns a success FinishResult instance and put to the OnFinish channel if it's not nil
func (*UnpackSettings) FinishError ¶
func (this *UnpackSettings) FinishError(err error) FinishResult
Finish returns an errored FinishResult instance and put to the OnFinish channel if it's not nil
func (*UnpackSettings) Progress ¶
func (this *UnpackSettings) Progress(total, index int, filename string)
Progress push a success ProgressState instance to the OnProgress channel.
func (*UnpackSettings) ProgressError ¶
func (this *UnpackSettings) ProgressError(err error, filename string)
ProgressError push an error ProgressState instance to the OnProgress channel.