wpk

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 14 Imported by: 1

README

Library to build and use data files packages.

Go Reference Go Report Card

Preamble

Software often uses a lot of data files and needs effective method to manage them and get quick access. Stitch them to single package and then get access by mapped memory is a good resolution.

Package keeps all files together with warranty that no any file will be deleted, moved or changed separately from others during software is running, it's snapshot of entire development workflow. Package saves disk space due to except file system granulation, especially if many small files are packed together. Package allows to lock fragment of single file to get access to mapped memory.

Capabilities

  • Package read and write API.
  • Lua-scripting API.
  • Virtual file system.
  • Set of associated tags with each file.
  • No sensible limits for package size.
  • Access to package by file mapping, as to slice, as to file.
  • Package can be formed by several steps.
  • Package can be used as insert-read database.

Structure

Library have root wpk module that used by any code working with .wpk packages. And modules to build utilities for packing/unpacking data files to package:

  • wpk Places data files into single package, extracts them, and gives API for access to package.

  • wpk/bulk Wrapper for package to hold WPK-file whole content as a slice. Actual for small packages (size is much less than the amount of RAM).

  • wpk/mmap Wrapper for package to get access to nested files as to memory mapped blocks. Actual for medium size packages (size correlates with the RAM amount).

  • wpk/fsys Wrapper for package to get access to nested files by OS files. Actual for large packages (size is much exceeds the amount of RAM) or large nested files.

  • wpk/luawpk Package writer with package building process scripting using Lua 5.1. Typical script workflow is to create package for writing, setup some options, put group of files to package, and finalize it.

  • wpk/test Contains some Lua-scripts to test wpk/luawpk module and learn scripting API opportunities.

  • wpk/util/pack Small simple utility designed to pack a directory, or a list of directories into an package.

  • wpk/util/extract Small simple utility designed to extract all packed files from package, or list of packages to given directory.

  • wpk/util/build Utility for the packages programmable building, based on wpk/luawpk module.

Compiled binaries of utilities can be downloaded in Releases section.

How to use

At first, install Golang minimum 1.18 version for last version of this package, and get this package:

go get github.com/schwarzlichtbezirk/wpk

Then you can make simple package with files at test/media directory by command:

go run github.com/schwarzlichtbezirk/wpk/util/pack --src=${GOPATH}/src/github.com/schwarzlichtbezirk/wpk/test/media --dst=${GOPATH}/bin/media.wpk

It's runs utility that receives source directory full path and destination package full path. ${GOPATH} at command line directory path replaced by GOPATH environment variable value. To place any other environment variable VAR you can by ${VAR}. In this sample package placed into bin directory with other compiled golang binary files.

To extract files from this media.wpk package run command:

go run github.com/schwarzlichtbezirk/wpk/util/extract --md --src=${GOPATH}/bin/media.wpk --dst=${GOPATH}/bin/media

and see files in directory ${GOPATH}/bin/media.

To build package at development workflow you can by build utility. It can put files into package from any different paths with given names, and bind addition tags to each file, such as MIME types, keywords, CRC, MD5, SHA256 and others. Run this command to see how its work:

go run github.com/schwarzlichtbezirk/wpk/util/build ${GOPATH}/src/github.com/schwarzlichtbezirk/wpk/test/build.lua

and see build.wpk file in binary directory near compiled output.

WPK-format

Package consist of 3 sections:

  1. Header, constantly 64 bytes. Starts with signature (24 bytes), then follow 8 bytes with used at package types sizes, file tags table offset and table size (8+8 bytes), and bata block offset and size (8+8 bytes).

  2. Bare data files blocks.

  3. File tags set table. Contains list of tagset for each file alias. Each tagset must contain some requered fields: it's ID, file size, file offset in package, file name (path), creation time. Package can have common description stored as tagset with empty name. This tagset is placed as first record in file tags table.

Existing package can be opened to append new files, in this case new files blocks will be posted to tags sets old place.

Package can be splitted in two files: 1) file with header and tags table, .wpt-file, it's a short file in most common, and 2) file with data files block, typically .wpd-file. In this case package is able for reading during new files packing to package. If process of packing new files will be broken by any case, package remains accessible with information pointed at last header record.

Lua-scripting API

build utility receives one or more Lua-scripts that maneges package building workflow. Typical sequence is to create new package, setup common properties, put files and add aliases with some tags if it necessary, and complete package building. See whole script API documentation in header comment of api.lua script, and sample package building algorithm below.

step1.lua and step2.lua scripts shows sample how to create new package at step1:

go run github.com/schwarzlichtbezirk/wpk/util/build ${GOPATH}/src/github.com/schwarzlichtbezirk/wpk/test/step1.lua

and later append to exising package new files at step2 call:

go run github.com/schwarzlichtbezirk/wpk/util/build ${GOPATH}/src/github.com/schwarzlichtbezirk/wpk/test/step2.lua

packdir.lua script has function that can be used to put to package directory with original tree hierarchy.

WPK API usage

See godoc with API description, and wpk_test.go for usage samples.

On your program initialisation open prepared wpk-package by Package.OpenFTT call. It reads tags sets of package on this call and has no any others reading of tags sets later. Tagset_t structure helps you to implement custom fs.FS to provide local file system and route it by http.FileServer. wpk/bulk, wpk/mmap and wpk/fsys modules already has file system interface implementation. So, you can use mmap.OpenPackage to open package as memory-mapped file and ReadFile-call to get a slice with some file content.

Documentation

Index

Examples

Constants

View Source
const (
	Signature = "Whirlwind 3.4 Package   " // package is ready for use
	Prebuild  = "Whirlwind 3.4 Prebuild  " // package is in building progress
)

File format signatures.

View Source
const (
	TIDnone = 0

	TIDoffset = 1  // required, defenid at TypeSize
	TIDsize   = 2  // required, defenid at TypeSize
	TIDpath   = 3  // required, unique, string
	TIDfid    = 4  // unique, defenid at TypeSize
	TIDmtime  = 5  // required for files, 8/12 bytes (mod-time)
	TIDatime  = 6  // 8/12 bytes (access-time)
	TIDctime  = 7  // 8/12 bytes (change-time)
	TIDbtime  = 8  // 8/12 bytes (birth-time)
	TIDattr   = 9  // uint32
	TIDmime   = 10 // string

	TIDcrc32ieee = 11 // uint32, CRC-32-IEEE 802.3, poly = 0x04C11DB7, init = -1
	TIDcrc32c    = 12 // uint32, (Castagnoli), poly = 0x1EDC6F41, init = -1
	TIDcrc32k    = 13 // uint32, (Koopman), poly = 0x741B8CD7, init = -1
	TIDcrc64iso  = 14 // uint64, poly = 0xD800000000000000, init = -1

	TIDmd5    = 20 // [16]byte
	TIDsha1   = 21 // [20]byte
	TIDsha224 = 22 // [28]byte
	TIDsha256 = 23 // [32]byte
	TIDsha384 = 24 // [48]byte
	TIDsha512 = 25 // [64]byte

	TIDtmbimg   = 100 // []byte, thumbnail image (icon)
	TIDtmbmime  = 101 // string, MIME type of thumbnail image
	TIDlabel    = 110 // string
	TIDlink     = 111 // string
	TIDkeywords = 112 // string
	TIDcategory = 113 // string
	TIDversion  = 114 // string
	TIDauthor   = 115 // string
	TIDcomment  = 116 // string
)

List of predefined tags IDs.

View Source
const (
	SignSize   = 24 // SignSize - signature field size.
	HeaderSize = 64 // HeaderSize - package header size in bytes.
)
View Source
const (
	PTStidsz  = iota // Index of "tag ID" type size.
	PTStagsz         // Index of "tag size" type size.
	PTStssize        // Index of "tagset size" type size.
)

Variables

View Source
var (
	ErrSignPre = errors.New("package is not ready")
	ErrSignBad = errors.New("signature does not pass")
	ErrSignFTT = errors.New("header contains incorrect data")

	ErrSizeFOffset = errors.New("size of file offset type is not in set {4, 8}")
	ErrSizeFSize   = errors.New("size of file size type is not in set {4, 8}")
	ErrSizeFID     = errors.New("size of file ID type is not in set {2, 4, 8}")
	ErrSizeTID     = errors.New("size of tag ID type is not in set {1, 2, 4}")
	ErrSizeTSize   = errors.New("size of tag size type is not in set {1, 2, 4}")
	ErrSizeTSSize  = errors.New("size of tagset size type is not in set {2, 4}")
	ErrCondFSize   = errors.New("size of file size type should be not more than file offset size")
	ErrCondTID     = errors.New("size of tag ID type should be not more than tagset size")
	ErrCondTSize   = errors.New("size of tag size type should be not more than tagset size")
	ErrRangeTSSize = errors.New("tagset size value is exceeds out of the type dimension")

	ErrNoTag    = errors.New("tag with given ID not found")
	ErrNoPath   = errors.New("file name is absent")
	ErrNoOffset = errors.New("file offset is absent")
	ErrOutOff   = errors.New("file offset is out of bounds")
	ErrNoSize   = errors.New("file size is absent")
	ErrOutSize  = errors.New("file size is out of bounds")
)

Errors on WPK-API.

View Source
var ToSlash = filepath.ToSlash

ToSlash brings filenames to true slashes.

Functions

func Envfmt added in v1.1.0

func Envfmt(p string) string

Envfmt replaces environment variables entries in file path to there values. Environment variables must be enclosed as ${...} in string.

func MakeDataPath added in v1.3.0

func MakeDataPath(fpath string) string

MakeDataPath receives file path and returns it with ".wpf" extension. It hepls to open splitted package.

func MakeTagsPath added in v1.3.0

func MakeTagsPath(fpath string) string

MakeTagsPath receives file path and returns it with ".wpt" extension. It hepls to open splitted package.

func Normalize added in v1.1.0

func Normalize(fpath string) string

Normalize brings file path to normalized form. It makes argument lowercase, change back slashes to normal slashes. Normalized path is the key to FTT map.

func PathExists added in v1.1.0

func PathExists(path string) (bool, error)

PathExists check up file or directory existence.

func ReadUint added in v1.3.2

func ReadUint(r io.Reader, l byte) (data uint, err error)

ReadUint reads from stream unsigned integer with given size in bytes. Size can be 1, 2, 4, 8.

func ReadUintBuf added in v1.3.2

func ReadUintBuf(b []byte) (r uint)

ReadUintBuf reads unsigned integer from buffer of predefined size. Dimension of integer depended from size of buffer, size can be 1, 2, 4, 8.

func WriteUint added in v1.3.2

func WriteUint(w io.Writer, data uint, l byte) (err error)

WriteUint writes to stream given unsigned integer with given size in bytes. Size can be 1, 2, 4, 8.

func WriteUintBuf added in v1.3.2

func WriteUintBuf(b []byte, v uint)

WriteUintBuf writes unsigned integer into buffer with predefined size. Size of buffer can be 1, 2, 4, 8.

Types

type ErrTag

type ErrTag struct {
	What error  // error message
	Key  string // normalized file name
	TID  uint   // tag ID
}

ErrTag is error on some field of tags set.

func (*ErrTag) Error

func (e *ErrTag) Error() string

func (*ErrTag) Unwrap

func (e *ErrTag) Unwrap() error

type FTT_t added in v1.3.0

type FTT_t struct {
	sync.Map
	// contains filtered or unexported fields
}

File tags table. Keys - package filenames in lower case, values - tagset slices.

func (*FTT_t) DelTagset added in v1.3.0

func (ftt *FTT_t) DelTagset(fkey string)

DelTagset deletes tagset with given filename key.

func (*FTT_t) Enum added in v1.3.0

func (ftt *FTT_t) Enum(f func(string, *Tagset_t) bool)

Enum calls given closure for each tagset in package. Skips package info.

func (*FTT_t) GetDelTagset added in v1.3.0

func (ftt *FTT_t) GetDelTagset(fkey string) (ts *Tagset_t, ok bool)

GetDelTagset deletes the tagset for a key, returning the previous tagset if any.

func (*FTT_t) HasTagset added in v1.3.0

func (ftt *FTT_t) HasTagset(fkey string) (ok bool)

HasTagset check up that tagset with given filename key is present.

func (*FTT_t) Info added in v1.3.0

func (ftt *FTT_t) Info() *Tagset_t

Info returns package information tagset, and stores if it not present before.

func (*FTT_t) NewTagset added in v1.3.3

func (ftt *FTT_t) NewTagset() *Tagset_t

NewTagset creates new empty tagset based on predefined TID type size and tag size type.

func (*FTT_t) Open added in v1.3.3

func (ftt *FTT_t) Open(dir string) (df fs.ReadDirFile, err error)

Open returns ReadDirFile structure associated with group of files in package pooled with common directory prefix. Usable to implement fs.FileSystem interface.

func (*FTT_t) ReadDir added in v1.3.3

func (ftt *FTT_t) ReadDir(dir string, n int) (matches []fs.DirEntry, err error)

ReadDir returns fs.FileInfo array with nested into given package directory presentation. It's core function for ReadDirFile and ReadDirFS structures.

func (*FTT_t) ReadFrom added in v1.3.0

func (ftt *FTT_t) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads file tags table whole content from the given stream.

func (*FTT_t) SetTagset added in v1.3.0

func (ftt *FTT_t) SetTagset(fkey string, ts *Tagset_t)

SetTagset puts tagset with given filename key.

func (*FTT_t) Tagset added in v1.3.0

func (ftt *FTT_t) Tagset(fkey string) (ts *Tagset_t, ok bool)

Tagset returns tagset with given filename key, if it found.

func (*FTT_t) WriteTo added in v1.3.0

func (ftt *FTT_t) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes file tags table whole content to the given stream.

type FileReader added in v1.2.0

type FileReader interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	Size() int64
}

FileReader is interface for nested package files access.

type Header struct {
	// contains filtered or unexported fields
}

Header - package header.

func (*Header) DataPos added in v1.3.0

func (hdr *Header) DataPos() (uint64, uint64)

DataPos returns data files block offset and size.

func (*Header) IsReady added in v1.3.0

func (hdr *Header) IsReady() (err error)

IsReady determines that package is ready for read the data.

func (*Header) IsSplitted added in v1.3.0

func (hdr *Header) IsSplitted() bool

IsSplitted returns true if package is splitted on tags and data files.

func (*Header) PTS added in v1.3.2

func (hdr *Header) PTS(idx int) byte

PTS is getter for sizes of package types.

func (*Header) ReadFrom added in v1.1.0

func (hdr *Header) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads header from stream as binary data of constant length in little endian order.

func (*Header) WriteTo added in v1.1.0

func (hdr *Header) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes header to stream as binary data of constant length in little endian order.

type NestedFile added in v1.2.0

type NestedFile interface {
	fs.File
	FileReader
}

NestedFile is interface for access to nested into package files.

type PackDirLogger added in v1.3.0

type PackDirLogger func(r io.ReadSeeker, ts *Tagset_t) error

PackDirLogger is function called during PackDir processing after each file with OS file object and inserted tagset, that can be modified.

type Package

type Package struct {
	Header
	FTT_t
	// contains filtered or unexported fields
}

Package structure contains all data needed for package representation.

func NewPackage added in v1.3.2

func NewPackage(pts TypeSize) (pack *Package)

NewPackage returns pointer to new initialized Package structure.

func (*Package) Append added in v1.3.0

func (pack *Package) Append(wpt, wpf io.WriteSeeker) (err error)

Append writes prebuild header for previously opened package to append new files.

func (*Package) BaseTagset added in v1.3.3

func (pack *Package) BaseTagset(offset, size uint, fpath string) *Tagset_t

BaseTagset returns new tagset based on predefined TID type size and tag size type, and puts file offset and file size into tagset with predefined sizes.

func (*Package) Begin added in v1.3.0

func (pack *Package) Begin(wpt io.WriteSeeker) (err error)

Begin writes prebuild header for new empty package.

func (*Package) Glob

func (pack *Package) Glob(pattern string) (res []string, err error)

Glob returns the names of all files in package matching pattern or nil if there is no matching file.

Example
package main

import (
	"log"
	"os"

	"github.com/schwarzlichtbezirk/wpk"
)

func main() {
	var err error

	// Open package file for reading
	var f *os.File
	if f, err = os.Open("example.wpk"); err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	// Open package files tags table
	var pack = &wpk.Package{}
	if err = pack.OpenFTT(f); err != nil {
		log.Fatal(err)
	}

	// Get all JPEG-files in subdirectories
	var res []string
	if res, err = pack.Glob("*/*.jpg"); err != nil {
		log.Fatal(err)
	}
	// and print them
	for _, fname := range res {
		log.Println(fname)
	}
}
Output:

func (*Package) Init added in v1.3.2

func (pack *Package) Init(pts TypeSize)

Init performs initialization for given Package structure.

func (*Package) OpenFTT added in v1.3.0

func (pack *Package) OpenFTT(r io.ReadSeeker) (err error)

Opens package for reading. At first it checkups file signature, then reads records table, and reads file tagset table. Tags set for each file must contain at least file offset, file size, file ID and file name.

Example
package main

import (
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/schwarzlichtbezirk/wpk"
)

func main() {
	var err error

	// Open package file for reading
	var f *os.File
	if f, err = os.Open("example.wpk"); err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	// Open package files tags table
	var pack = &wpk.Package{}
	if err = pack.OpenFTT(f); err != nil {
		log.Fatal(err)
	}

	// How many records in package
	var m = map[uint]struct{}{}
	var n = 0
	pack.Enum(func(fkey string, ts *wpk.Tagset_t) bool {
		if n < 5 { // print not more than 5 file names from package
			log.Println(fkey)
		}
		if offset, ok := ts.Uint(wpk.TIDoffset); ok {
			m[offset] = struct{}{}
		}
		n++
		return true
	})

	// Format package information
	var items []string
	items = append(items, fmt.Sprintf("records: %d", len(m)))
	items = append(items, fmt.Sprintf("aliases: %d", n))
	if ts, ok := pack.Tagset(""); ok { // get package info if it present
		if size, ok := ts.Uint(wpk.TIDsize); ok {
			items = append(items, fmt.Sprintf("datasize: %d", size))
		}
		if str, ok := ts.String(wpk.TIDlabel); ok {
			items = append(items, fmt.Sprintf("label: %s", str))
		}
	}
	log.Println(strings.Join(items, ", "))
}
Output:

func (*Package) PackData added in v1.3.0

func (pack *Package) PackData(w io.WriteSeeker, r io.Reader, fpath string) (ts *Tagset_t, err error)

PackData puts data streamed by given reader into package as a file and associate keyname "kpath" with it.

func (*Package) PackDir added in v1.3.0

func (pack *Package) PackDir(w io.WriteSeeker, dirname, prefix string, logger PackDirLogger) (err error)

PackDir puts all files of given folder and it's subfolders into package. Logger function can be nil.

func (*Package) PackFile added in v1.3.0

func (pack *Package) PackFile(w io.WriteSeeker, file *os.File, kpath string) (ts *Tagset_t, err error)

PackFile puts file with given file handle into package and associate keyname "kpath" with it.

func (*Package) PutAlias added in v1.3.0

func (pack *Package) PutAlias(oldname, newname string) error

PutAlias makes clone tagset with file name 'oldname' and replace name tag in it to 'newname'. Keeps link to original file name.

func (*Package) Rename added in v1.3.0

func (pack *Package) Rename(oldname, newname string) error

Rename tagset with file name 'oldname' to 'newname'. Keeps link to original file name.

func (*Package) Sync added in v1.3.0

func (pack *Package) Sync(wpt, wpf io.WriteSeeker) (err error)

Sync writes actual file tags table and true signature with settings.

type Packager

type Packager interface {
	io.Closer
	fs.SubFS
	fs.StatFS
	fs.GlobFS
	fs.ReadFileFS
	fs.ReadDirFS
}

Packager refers to package data access management implementation.

type ReadDirFile added in v1.1.0

type ReadDirFile struct {
	Tagset_t // has fs.FileInfo interface
	FTT      *FTT_t
}

ReadDirFile is a directory file whose entries can be read with the ReadDir method. fs.ReadDirFile interface implementation.

func (*ReadDirFile) Close added in v1.1.0

func (f *ReadDirFile) Close() error

Close is for fs.ReadDirFile interface compatibility.

func (*ReadDirFile) Read added in v1.1.0

func (f *ReadDirFile) Read(b []byte) (n int, err error)

Read is for fs.ReadDirFile interface compatibility.

func (*ReadDirFile) ReadDir added in v1.1.0

func (f *ReadDirFile) ReadDir(n int) (matches []fs.DirEntry, err error)

ReadDir returns fs.FileInfo array with nested into given package directory presentation.

func (*ReadDirFile) Stat added in v1.1.0

func (f *ReadDirFile) Stat() (fs.FileInfo, error)

Stat is for fs.ReadDirFile interface compatibility.

type Tag_t added in v1.3.0

type Tag_t []byte

Tag_t - file description item.

func TagBool

func TagBool(val bool) Tag_t

TagBool is boolean tag constructor.

func TagByte

func TagByte(val byte) Tag_t

TagByte is Byte tag constructor.

func TagNumber

func TagNumber(val float64) Tag_t

TagNumber is 64-bit float tag constructor.

func TagString

func TagString(val string) Tag_t

TagString is string tag constructor.

func TagTime added in v1.3.1

func TagTime(val time.Time) Tag_t

TagTime is 12-bytes UNIX time tag constructor.

func TagUint added in v1.3.2

func TagUint(val uint) Tag_t

TagUint is unspecified size unsigned int tag constructor.

func TagUint16

func TagUint16(val uint16) Tag_t

TagUint16 is 16-bit unsigned int tag constructor.

func TagUint32

func TagUint32(val uint32) Tag_t

TagUint32 is 32-bit unsigned int tag constructor.

func TagUint64

func TagUint64(val uint64) Tag_t

TagUint64 is 64-bit unsigned int tag constructor.

func TagUint8 added in v1.3.0

func TagUint8(val uint8) Tag_t

TagUint8 is 8-bit unsigned int tag constructor.

func TagUintLen added in v1.3.2

func TagUintLen(val uint, l byte) Tag_t

TagUintLen is unsigned int tag constructor with specified length in bytes.

func TagUnix added in v1.3.1

func TagUnix(val time.Time) Tag_t

TagUnix is 8-bytes UNIX time in milliseconds tag constructor.

func (Tag_t) Bool added in v1.3.0

func (t Tag_t) Bool() (bool, bool)

Bool is boolean tag converter.

func (Tag_t) Byte added in v1.3.0

func (t Tag_t) Byte() (byte, bool)

Byte tag converter.

func (Tag_t) Number added in v1.3.0

func (t Tag_t) Number() (float64, bool)

Number is 64-bit float tag converter.

func (Tag_t) String added in v1.3.0

func (t Tag_t) String() (string, bool)

String tag converter.

func (Tag_t) Time added in v1.3.1

func (t Tag_t) Time() (time.Time, bool)

Time is 8/12-bytes time tag converter.

func (Tag_t) Uint added in v1.3.0

func (t Tag_t) Uint() (ret uint, ok bool)

Uint is unspecified size unsigned int tag converter.

func (Tag_t) Uint16 added in v1.3.0

func (t Tag_t) Uint16() (uint16, bool)

Uint16 is 16-bit unsigned int tag converter.

func (Tag_t) Uint32 added in v1.3.0

func (t Tag_t) Uint32() (uint32, bool)

Uint32 is 32-bit unsigned int tag converter.

func (Tag_t) Uint64 added in v1.3.0

func (t Tag_t) Uint64() (uint64, bool)

Uint64 is 64-bit unsigned int tag converter.

func (Tag_t) Uint8 added in v1.3.0

func (t Tag_t) Uint8() (uint8, bool)

Uint8 is 8-bit unsigned int tag converter.

type Tagger

type Tagger interface {
	OpenTagset(*Tagset_t) (NestedFile, error)
	Tagset(string) (*Tagset_t, bool)
	Enum(func(string, *Tagset_t) bool)
}

Tagger provides file tags access.

type TagsetIterator added in v1.3.0

type TagsetIterator struct {
	Tagset_t
	// contains filtered or unexported fields
}

TagsetIterator helps to iterate through all tags.

func (*TagsetIterator) Del added in v1.3.0

func (tsi *TagsetIterator) Del(tid uint) bool

Del is the stub to disable any changes to data content of iterator.

func (*TagsetIterator) Failed added in v1.3.0

func (tsi *TagsetIterator) Failed() bool

Failed points that iterator is finished by broken tagset state.

func (*TagsetIterator) Next added in v1.3.0

func (tsi *TagsetIterator) Next() (ok bool)

Next carries to the next tag position.

Example
var ts = wpk.MakeTagset(nil, tidsz, tagsz).
	Put(wpk.TIDpath, wpk.TagString("picture.jpg")).
	Put(wpk.TIDmtime, wpk.TagTime(time.Now())).
	Put(wpk.TIDmime, wpk.TagString("image/jpeg"))
var tsi = ts.Iterator()
for tsi.Next() {
	fmt.Printf("tid=%d, len=%d\n", tsi.TID(), tsi.TagLen())
}
Output:

tid=3, len=11
tid=5, len=12
tid=10, len=10

func (*TagsetIterator) Passed added in v1.3.0

func (tsi *TagsetIterator) Passed() bool

Passed returns true if the end of iterations is successfully reached.

Example
var slice = []byte{
	3, 0, 4, 0, 10, 0, 0, 0,
	4, 0, 12, 0, 115, 111, 109, 101, 102, 105, 108, 101, 46, 100, 97, 116,
}
var tsi = wpk.MakeTagset(slice, tidsz, tagsz).Iterator()
for tsi.Next() {
	// place some handler code here
}
fmt.Println(tsi.Passed())
Output:

true

func (*TagsetIterator) Put added in v1.3.0

func (tsi *TagsetIterator) Put(tid uint, tag Tag_t) *Tagset_t

Put is the stub to disable any changes to data content of iterator.

func (*TagsetIterator) Reset added in v1.3.0

func (tsi *TagsetIterator) Reset()

Reset restarts iterator for new iterations loop.

func (*TagsetIterator) Set added in v1.3.0

func (tsi *TagsetIterator) Set(tid uint, tag Tag_t) bool

Set is the stub to disable any changes to data content of iterator.

func (*TagsetIterator) TID added in v1.3.0

func (tsi *TagsetIterator) TID() uint

TID returns the tag ID of the last readed tag.

func (*TagsetIterator) Tag added in v1.3.0

func (tsi *TagsetIterator) Tag() Tag_t

Tag returns tag slice of the last readed tag content.

func (*TagsetIterator) TagLen added in v1.3.0

func (tsi *TagsetIterator) TagLen() int

TagLen returns length of last readed tag content.

type Tagset_t added in v1.3.0

type Tagset_t struct {
	// contains filtered or unexported fields
}

Tagset_t is slice of bytes with tags set. Length of slice can be not determined to record end, i.e. slice starts at record beginning (at number of tags), and can continues after record end. fs.FileInfo interface implementation.

func GetPackageInfo added in v1.3.0

func GetPackageInfo(r io.ReadSeeker, tidsz, tagsz byte) (ts *Tagset_t, err error)

GetPackageInfo returns tagset with package information. It's a quick function to get info from the file.

func MakeTagset added in v1.3.0

func MakeTagset(data []byte, tidsz, tagsz byte) *Tagset_t

MakeTagset returns tagset with given slice.

func (*Tagset_t) AccessTime added in v1.3.1

func (ts *Tagset_t) AccessTime() time.Time

AccessTime returns file access timestamp of nested into package file. times.Timespec implementation.

func (*Tagset_t) BirthTime added in v1.3.1

func (ts *Tagset_t) BirthTime() time.Time

BirthTime returns file access timestamp of nested into package file. times.Timespec implementation.

func (*Tagset_t) Bool added in v1.3.0

func (ts *Tagset_t) Bool(tid uint) (bool, bool)

Bool is boolean tag getter.

func (*Tagset_t) Byte added in v1.3.0

func (ts *Tagset_t) Byte(tid uint) (byte, bool)

Byte tag getter.

func (*Tagset_t) ChangeTime added in v1.3.1

func (ts *Tagset_t) ChangeTime() time.Time

ChangeTime returns file change timestamp of nested into package file. times.Timespec implementation.

func (*Tagset_t) Data added in v1.3.0

func (ts *Tagset_t) Data() []byte

Data returns whole tagset content.

func (*Tagset_t) Del added in v1.3.0

func (ts *Tagset_t) Del(tid uint) bool

Del deletes tag with given ID.

func (*Tagset_t) Get added in v1.3.0

func (ts *Tagset_t) Get(tid uint) (Tag_t, bool)

GetTag returns Tag_t with given identifier. If tag is not found, slice content is broken, returns false.

func (*Tagset_t) Has added in v1.3.0

func (ts *Tagset_t) Has(tid uint) bool

Has checks existence of tag with given ID.

func (*Tagset_t) HasBirthTime added in v1.3.1

func (ts *Tagset_t) HasBirthTime() bool

HasBirthTime is times.Timespec interface implementation. Returns whether birth timestamp is present.

func (*Tagset_t) HasChangeTime added in v1.3.1

func (ts *Tagset_t) HasChangeTime() bool

HasChangeTime is times.Timespec interface implementation. Returns whether change timestamp is present.

func (*Tagset_t) Info added in v1.3.3

func (ts *Tagset_t) Info() (fs.FileInfo, error)

Info returns the FileInfo for the file or subdirectory described by the entry. fs.DirEntry interface implementation.

func (*Tagset_t) IsDir added in v1.3.0

func (ts *Tagset_t) IsDir() bool

IsDir detects that object presents a directory. Directory can not have file ID. fs.FileInfo implementation.

func (*Tagset_t) Iterator added in v1.3.0

func (ts *Tagset_t) Iterator() *TagsetIterator

Iterator clones this tagset to iterate through all tags.

func (*Tagset_t) ModTime added in v1.3.0

func (ts *Tagset_t) ModTime() time.Time

ModTime returns file modification timestamp of nested into package file. fs.FileInfo & times.Timespec implementation.

func (*Tagset_t) Mode added in v1.3.0

func (ts *Tagset_t) Mode() fs.FileMode

Mode is for fs.FileInfo interface compatibility.

func (*Tagset_t) Name added in v1.3.0

func (ts *Tagset_t) Name() string

Name returns base name of nested into package file. fs.FileInfo implementation.

func (*Tagset_t) Num added in v1.3.0

func (ts *Tagset_t) Num() (n int)

Num returns number of tags in tagset.

func (*Tagset_t) Number added in v1.3.0

func (ts *Tagset_t) Number(tid uint) (float64, bool)

Number is 64-bit float tag getter.

func (*Tagset_t) Path added in v1.3.0

func (ts *Tagset_t) Path() string

Path returns path of nested into package file. Path required to be present in any tagset.

func (*Tagset_t) Pos added in v1.3.3

func (ts *Tagset_t) Pos() (offset, size uint)

Pos returns file offset and file size in package. Those values required to be present in any tagset.

func (*Tagset_t) Put added in v1.3.0

func (ts *Tagset_t) Put(tid uint, tag Tag_t) *Tagset_t

Put appends new tag to tagset. Can be used in chain calls at initialization.

func (*Tagset_t) Set added in v1.3.0

func (ts *Tagset_t) Set(tid uint, tag Tag_t) bool

Set replaces tag with given ID and equal size, or appends it to tagset. Returns true if new one added.

func (*Tagset_t) Size added in v1.3.0

func (ts *Tagset_t) Size() int64

Size returns size of nested into package file. fs.FileInfo implementation.

func (*Tagset_t) String added in v1.3.0

func (ts *Tagset_t) String(tid uint) (string, bool)

String tag getter.

func (*Tagset_t) Sys added in v1.3.0

func (ts *Tagset_t) Sys() interface{}

Sys is for fs.FileInfo interface compatibility.

func (*Tagset_t) Time added in v1.3.1

func (ts *Tagset_t) Time(tid uint) (time.Time, bool)

Time is time tag getter.

func (*Tagset_t) Type added in v1.3.3

func (ts *Tagset_t) Type() fs.FileMode

Type is for fs.DirEntry interface compatibility.

func (*Tagset_t) Uint added in v1.3.0

func (ts *Tagset_t) Uint(tid uint) (uint, bool)

Uint is unspecified size unsigned int tag getter.

func (*Tagset_t) Uint16 added in v1.3.0

func (ts *Tagset_t) Uint16(tid uint) (uint16, bool)

Uint16 is 16-bit unsigned int tag getter. Conversion can be used to get signed 16-bit integers.

func (*Tagset_t) Uint32 added in v1.3.0

func (ts *Tagset_t) Uint32(tid uint) (uint32, bool)

Uint32 is 32-bit unsigned int tag getter. Conversion can be used to get signed 32-bit integers.

func (*Tagset_t) Uint64 added in v1.3.0

func (ts *Tagset_t) Uint64(tid uint) (uint64, bool)

Uint64 is 64-bit unsigned int tag getter. Conversion can be used to get signed 64-bit integers.

type TypeSize added in v1.3.2

type TypeSize [8]byte

TypeSize is set of package types sizes.

func (TypeSize) Checkup added in v1.3.2

func (pts TypeSize) Checkup() error

Checkup performs check up sizes of all types in bytes used in current WPK-file.

type WriteSeekCloser added in v1.3.0

type WriteSeekCloser interface {
	io.Writer
	io.Seeker
	io.Closer
}

WriteSeekCloser is typical useful interface for package writing.

Directories

Path Synopsis
util

Jump to

Keyboard shortcuts

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