common

package
v0.0.0-...-5ea318d Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package common is the common functions and types for the packer and unpacker packages.

Index

Constants

View Source
const (
	// FFolder is the bit for folder record
	FFolder uint8 = 0

	// FArchive is the bit for archive represented folder
	FArchive uint8 = 1

	// FData is the bit for file record
	FData uint8 = 2
)

Variables

View Source
var (
	// Order is the used binary endian order
	Order = binary.BigEndian
)

Functions

func AddFileToFolder

func AddFileToFolder(fold *Folder, f *File) error

AddFileToFolder will add File object to Folder object

func AddFolderToFolder

func AddFolderToFolder(dest *Folder, src *Folder) error

AddFolderToFolder will add subfolder Folder object into Folder object

func ClearDirinfo

func ClearDirinfo()

ClearDirinfo is for Dirinfo and Offset maps reset.

func RemoveDirReq

func RemoveDirReq(dir string) error

RemoveDirReq will remove folder reqursively.

based on https://stackoverflow.com/questions/33450980/golang-remove-all-contents-of-a-directory

func SetOffset

func SetOffset(offset uint32, hash []byte)

SetOffset apply hash to the data offset value.

func ToBinary

func ToBinary(h *Header) []byte

ToBinary will transform header into bytearray

Types

type ContainerType

type ContainerType struct {
	Name      string `json:"name"`
	Extension string `json:"ext"`
}

ContainerType is the type of container

func IsContainer

func IsContainer(filename string) (*ContainerType, bool)

IsContainer check file name for .zip or .jar extensions

type DataHeader

type DataHeader []*DataRecord

DataHeader is the array of the pointers to the DataRecord objects.

type DataRecord

type DataRecord struct {
	Offset uint32 `json:"offset"`
	Size   uint32 `json:"size"`
	Hash   []byte `json:"hash"`
}

DataRecord is the type for file representation in archive header.

type Dirinfo

type Dirinfo map[string][]*File

Dirinfo is the hash to files map, used as basic structure for output file header.

func GetDirinfo

func GetDirinfo() *Dirinfo

GetDirinfo will return current state of the DirInfo object

func (Dirinfo) String

func (di Dirinfo) String() string

type File

type File struct {
	Name    string `json:"name"`
	Size    int    `json:"size"`
	Hashsum []byte `json:"hash"`
}

File is the representation of the file entity. This type contains filename, filesize and hashsumm.

func NewFile

func NewFile(filename string, body []byte) (*File, bool)

NewFile will create new File object

type Folder

type Folder struct {
	IsContainer bool      `json:"isContainer"`
	Name        string    `json:"name"`
	Folders     []*Folder `json:"folders"`
	Files       []*File   `json:"files"`
}

Folder is the representation of the disk folder OR archive.

func MkdirAll

func MkdirAll(fold *Folder, somepath string) (f *Folder, err error)

MkdirAll will create subfolders (if required) in the given folder.

func NewFolder

func NewFolder(foldername string, isContainer bool) Folder

NewFolder will create new Folder object.

func (*Folder) HasFolder

func (fold *Folder) HasFolder(name string) (*Folder, error)

HasFolder will search for subfolder name in the given folder.

func (Folder) String

func (f Folder) String() string

type FolderRecord

type FolderRecord struct {
	Parent     uint32 `json:"parentId"`
	Flags      uint8  `json:"flags"`
	Data       uint32 `json:"dataId"`
	Namelength uint8  `json:"namelen"`
	Name       []byte `json:"name"`
}

FolderRecord is the type for folder representation in archive header.

type Foldernode

type Foldernode interface {
	HasFolder(name string) (*Folder, error)
}

Foldernode is the interface, defined is the object has subfolder with the given name.

type FoldersHeader

type FoldersHeader []FolderRecord

FoldersHeader is the array of the FolderRecord objects

type Header struct {
	Folders FoldersHeader `json:"folders"`
	Data    DataHeader    `json:"data"`
	Size    uint32        `json:"datasize"`
}

Header is the structure of the archive header information.

func FromBinary

func FromBinary(b []byte) *Header

FromBinary will parse bytes array into new Header object

func NewHeader

func NewHeader(packedSize uint32) *Header

NewHeader will create new header object

func (*Header) FindDataOffset

func (h *Header) FindDataOffset(f *File) uint32

FindDataOffset will find data offset by hash of the given File object.

func (*Header) Fold

func (h *Header) Fold(parentID uint32, f *Folder) uint32

Fold will create new Folder record in header and link it with parent folder by parentID

func (*Header) Marshal

func (h *Header) Marshal(folder *Folder, offsets *Offset)

Marshal will serialize root folder and offests into headr object

func (*Header) Pack

func (h *Header) Pack(offset uint32, size uint32, hash []byte)

Pack will add new DataRecord into header

func (Header) String

func (h Header) String() string

type Offset

type Offset map[uint32][]byte

Offset is the file hashes by 4 bytes of file offset in _uncompressed_ data array.

func GetOffsets

func GetOffsets() *Offset

GetOffsets will return current state of the Offsets object

func (Offset) String

func (o Offset) String() string

type Packable

type Packable interface {
	Pack(offset uint32, size uint32, hash []byte)
}

Packable is the interface for objects, which can be packed.

Jump to

Keyboard shortcuts

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