icepacker

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2016 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENCRYPT_NONE = iota
	ENCRYPT_AES
)

Encryption enum constants

View Source
const (
	COMPRESS_NONE = iota
	COMPRESS_GZIP
)

Compression enum constants

View Source
const DEFAULT_PERMISSION = 0755
View Source
const FOOTER_SIZE = 8 + 4 + MAGIC_SIZE

FOOTER_SIZE is the size of footer

View Source
const HEADER_SIZE = MAGIC_SIZE + 1 + 1 + 1 + 8 + 8

HEADER_SIZE is the size of the Header

View Source
const MAGIC_SIZE = 5
View Source
const MagicBytes = "IPACK"

Magic bytes to identify the file format

View Source
const VERSION_1 = 1

Variables

View Source
var ByteOrder = binary.LittleEndian

Functions

func FixPath

func FixPath(path string) string

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

func TransformPack(data []byte, compression byte, encryption byte, key []byte) ([]byte, error)

TransformPack is transform the content of file to the package (encrypt, compress)

func TransformUnpack

func TransformUnpack(data []byte, compression byte, encryption byte, key []byte) ([]byte, error)

TransformUnpack is transform back the transformed file content to the real file

Types

type BundleFile

type BundleFile struct {
	Path           string
	File           *os.File
	FAT            FAT
	Header         *Header
	Footer         *Footer
	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) Close

func (this *BundleFile) Close() error

Close closes the bundle File

func (*BundleFile) Flush

func (this *BundleFile) Flush() error

Flush writes the footer of bundle

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

type BundleSettings struct {
	Compression byte
	Encryption  byte
	CipherKey   []byte
}

BundleSettings records the settings of the bundle file

type CipherSettings

type CipherSettings struct {
	Key       string
	Salt      string
	Iteration int
}

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

func FATFromJSON(buf []byte) (*FAT, error)

FATFromJSON build FAT struct from JSON string

func (FAT) JSON

func (fat FAT) JSON() ([]byte, error)

JSON convert the FAT to JSON string

func (FAT) String

func (fat FAT) String() string

String Convert the whole FAT to 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

func (FATItem) String

func (item FATItem) String() string

String convert the FAT item to string

type FinishResult

type FinishResult struct {
	Err       error
	FileCount int64
	Size      int64
	DupCount  int
	DupSize   int64
}

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 struct {
	Checksum uint32
	PackSize int64
	Magic    []byte
}

Footer is a struct for footer of package

func GetFooter

func GetFooter(pack io.Reader) (*Footer, error)

GetFooter reads the footer from the io.Reader

func NewFooter

func NewFooter() *Footer

NewFooter create a new Footer with default values

func (*Footer) Write

func (footer *Footer) Write(writer io.Writer) error

Write writes the Footer struct to the io.Writer

type Header struct {
	Magic    []byte
	Version  byte
	Encrypt  byte
	Compress byte
	FatSize  int64
	Created  int64
}

Header is the header of package

func GetHeader

func GetHeader(pack io.Reader) (*Header, error)

GetHeader reads the header from the io.Reader and returns a *Header struct

func NewHeader

func NewHeader(encryption, compression byte) *Header

NewHeader create a new Header with default values and set the encryption and compress types.

func (*Header) Write

func (header *Header) Write(writer io.Writer) error

Write writes the header to the io.Writer

type ListResult

type ListResult struct {
	Err error
	FAT *FAT
}

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

type ProgressState struct {
	Err         error
	Total       int
	Index       int
	CurrentFile string
}

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.

Jump to

Keyboard shortcuts

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