Documentation ¶
Index ¶
- Constants
- Variables
- func Envfmt(p string) string
- func MakeDataPath(fpath string) string
- func MakeTagsPath(fpath string) string
- func Normalize(fpath string) string
- func PathExists(path string) (bool, error)
- func ReadUint(r io.Reader, l byte) (data uint, err error)
- func ReadUintBuf(b []byte) (r uint)
- func WriteUint(w io.Writer, data uint, l byte) (err error)
- func WriteUintBuf(b []byte, v uint)
- type ErrTag
- type FTT_t
- func (ftt *FTT_t) DelTagset(fkey string)
- func (ftt *FTT_t) Enum(f func(string, *Tagset_t) bool)
- func (ftt *FTT_t) GetDelTagset(fkey string) (ts *Tagset_t, ok bool)
- func (ftt *FTT_t) HasTagset(fkey string) (ok bool)
- func (ftt *FTT_t) Info() *Tagset_t
- func (ftt *FTT_t) NewTagset() *Tagset_t
- func (ftt *FTT_t) Open(dir string) (df fs.ReadDirFile, err error)
- func (ftt *FTT_t) ReadDir(dir string, n int) (matches []fs.DirEntry, err error)
- func (ftt *FTT_t) ReadFrom(r io.Reader) (n int64, err error)
- func (ftt *FTT_t) SetTagset(fkey string, ts *Tagset_t)
- func (ftt *FTT_t) Tagset(fkey string) (ts *Tagset_t, ok bool)
- func (ftt *FTT_t) WriteTo(w io.Writer) (n int64, err error)
- type FileReader
- type Header
- type NestedFile
- type PackDirLogger
- type Package
- func (pack *Package) Append(wpt, wpf io.WriteSeeker) (err error)
- func (pack *Package) BaseTagset(offset, size uint, fpath string) *Tagset_t
- func (pack *Package) Begin(wpt io.WriteSeeker) (err error)
- func (pack *Package) Glob(pattern string) (res []string, err error)
- func (pack *Package) Init(pts TypeSize)
- func (pack *Package) OpenFTT(r io.ReadSeeker) (err error)
- func (pack *Package) PackData(w io.WriteSeeker, r io.Reader, fpath string) (ts *Tagset_t, err error)
- func (pack *Package) PackDir(w io.WriteSeeker, dirname, prefix string, logger PackDirLogger) (err error)
- func (pack *Package) PackFile(w io.WriteSeeker, file *os.File, kpath string) (ts *Tagset_t, err error)
- func (pack *Package) PutAlias(oldname, newname string) error
- func (pack *Package) Rename(oldname, newname string) error
- func (pack *Package) Sync(wpt, wpf io.WriteSeeker) (err error)
- type Packager
- type ReadDirFile
- type Tag_t
- func TagBool(val bool) Tag_t
- func TagByte(val byte) Tag_t
- func TagNumber(val float64) Tag_t
- func TagString(val string) Tag_t
- func TagTime(val time.Time) Tag_t
- func TagUint(val uint) Tag_t
- func TagUint16(val uint16) Tag_t
- func TagUint32(val uint32) Tag_t
- func TagUint64(val uint64) Tag_t
- func TagUint8(val uint8) Tag_t
- func TagUintLen(val uint, l byte) Tag_t
- func TagUnix(val time.Time) Tag_t
- func (t Tag_t) Bool() (bool, bool)
- func (t Tag_t) Byte() (byte, bool)
- func (t Tag_t) Number() (float64, bool)
- func (t Tag_t) String() (string, bool)
- func (t Tag_t) Time() (time.Time, bool)
- func (t Tag_t) Uint() (ret uint, ok bool)
- func (t Tag_t) Uint16() (uint16, bool)
- func (t Tag_t) Uint32() (uint32, bool)
- func (t Tag_t) Uint64() (uint64, bool)
- func (t Tag_t) Uint8() (uint8, bool)
- type Tagger
- type TagsetIterator
- func (tsi *TagsetIterator) Del(tid uint) bool
- func (tsi *TagsetIterator) Failed() bool
- func (tsi *TagsetIterator) Next() (ok bool)
- func (tsi *TagsetIterator) Passed() bool
- func (tsi *TagsetIterator) Put(tid uint, tag Tag_t) *Tagset_t
- func (tsi *TagsetIterator) Reset()
- func (tsi *TagsetIterator) Set(tid uint, tag Tag_t) bool
- func (tsi *TagsetIterator) TID() uint
- func (tsi *TagsetIterator) Tag() Tag_t
- func (tsi *TagsetIterator) TagLen() int
- type Tagset_t
- func (ts *Tagset_t) AccessTime() time.Time
- func (ts *Tagset_t) BirthTime() time.Time
- func (ts *Tagset_t) Bool(tid uint) (bool, bool)
- func (ts *Tagset_t) Byte(tid uint) (byte, bool)
- func (ts *Tagset_t) ChangeTime() time.Time
- func (ts *Tagset_t) Data() []byte
- func (ts *Tagset_t) Del(tid uint) bool
- func (ts *Tagset_t) Get(tid uint) (Tag_t, bool)
- func (ts *Tagset_t) Has(tid uint) bool
- func (ts *Tagset_t) HasBirthTime() bool
- func (ts *Tagset_t) HasChangeTime() bool
- func (ts *Tagset_t) Info() (fs.FileInfo, error)
- func (ts *Tagset_t) IsDir() bool
- func (ts *Tagset_t) Iterator() *TagsetIterator
- func (ts *Tagset_t) ModTime() time.Time
- func (ts *Tagset_t) Mode() fs.FileMode
- func (ts *Tagset_t) Name() string
- func (ts *Tagset_t) Num() (n int)
- func (ts *Tagset_t) Number(tid uint) (float64, bool)
- func (ts *Tagset_t) Path() string
- func (ts *Tagset_t) Pos() (offset, size uint)
- func (ts *Tagset_t) Put(tid uint, tag Tag_t) *Tagset_t
- func (ts *Tagset_t) Set(tid uint, tag Tag_t) bool
- func (ts *Tagset_t) Size() int64
- func (ts *Tagset_t) String(tid uint) (string, bool)
- func (ts *Tagset_t) Sys() interface{}
- func (ts *Tagset_t) Time(tid uint) (time.Time, bool)
- func (ts *Tagset_t) Type() fs.FileMode
- func (ts *Tagset_t) Uint(tid uint) (uint, bool)
- func (ts *Tagset_t) Uint16(tid uint) (uint16, bool)
- func (ts *Tagset_t) Uint32(tid uint) (uint32, bool)
- func (ts *Tagset_t) Uint64(tid uint) (uint64, bool)
- type TypeSize
- type WriteSeekCloser
Examples ¶
Constants ¶
const ( Signature = "Whirlwind 3.4 Package " // package is ready for use Prebuild = "Whirlwind 3.4 Prebuild " // package is in building progress )
File format signatures.
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 TIDcomment = 116 // string )
List of predefined tags IDs.
const ( SignSize = 24 // SignSize - signature field size. HeaderSize = 64 // HeaderSize - package header size in bytes. )
const ( PTStidsz = iota // Index of "tag ID" type size. PTStssize // Index of "tagset size" type size. )
Variables ¶
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.
var ToSlash = filepath.ToSlash
ToSlash brings filenames to true slashes.
Functions ¶
func Envfmt ¶ added in v1.1.0
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
MakeDataPath receives file path and returns it with ".wpf" extension. It hepls to open splitted package.
func MakeTagsPath ¶ added in v1.3.0
MakeTagsPath receives file path and returns it with ".wpt" extension. It hepls to open splitted package.
func Normalize ¶ added in v1.1.0
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
PathExists check up file or directory existence.
func ReadUint ¶ added in v1.3.2
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
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
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
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.
type FTT_t ¶ added in v1.3.0
File tags table. Keys - package filenames in lower case, values - tagset slices.
func (*FTT_t) Enum ¶ added in v1.3.0
Enum calls given closure for each tagset in package. Skips package info.
func (*FTT_t) GetDelTagset ¶ added in v1.3.0
GetDelTagset deletes the tagset for a key, returning the previous tagset if any.
func (*FTT_t) HasTagset ¶ added in v1.3.0
HasTagset check up that tagset with given filename key is present.
func (*FTT_t) Info ¶ added in v1.3.0
Info returns package information tagset, and stores if it not present before.
func (*FTT_t) NewTagset ¶ added in v1.3.3
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
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
ReadFrom reads file tags table whole content from the given stream.
type FileReader ¶ added in v1.2.0
FileReader is interface for nested package files access.
type Header ¶ added in v1.1.0
type Header struct {
// contains filtered or unexported fields
}
Header - package header.
func (*Header) IsReady ¶ added in v1.3.0
IsReady determines that package is ready for read the data.
func (*Header) IsSplitted ¶ added in v1.3.0
IsSplitted returns true if package is splitted on tags and data files.
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 ¶
Package structure contains all data needed for package representation.
func NewPackage ¶ added in v1.3.2
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
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 ¶
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) 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
PutAlias makes clone tagset with file name 'oldname' and replace name tag in it to 'newname'. Keeps link to original file name.
type ReadDirFile ¶ added in v1.1.0
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.
type Tag_t ¶ added in v1.3.0
type Tag_t []byte
Tag_t - file description item.
func TagUintLen ¶ added in v1.3.2
TagUintLen is unsigned int tag constructor with specified length in bytes.
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
MakeTagset returns tagset with given slice.
func (*Tagset_t) AccessTime ¶ added in v1.3.1
AccessTime returns file access timestamp of nested into package file. times.Timespec implementation.
func (*Tagset_t) BirthTime ¶ added in v1.3.1
BirthTime returns file access timestamp of nested into package file. times.Timespec implementation.
func (*Tagset_t) ChangeTime ¶ added in v1.3.1
ChangeTime returns file change timestamp of nested into package file. times.Timespec implementation.
func (*Tagset_t) Get ¶ added in v1.3.0
GetTag returns Tag_t with given identifier. If tag is not found, slice content is broken, returns false.
func (*Tagset_t) HasBirthTime ¶ added in v1.3.1
HasBirthTime is times.Timespec interface implementation. Returns whether birth timestamp is present.
func (*Tagset_t) HasChangeTime ¶ added in v1.3.1
HasChangeTime is times.Timespec interface implementation. Returns whether change timestamp is present.
func (*Tagset_t) Info ¶ added in v1.3.3
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
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
ModTime returns file modification timestamp of nested into package file. fs.FileInfo & times.Timespec implementation.
func (*Tagset_t) Name ¶ added in v1.3.0
Name returns base name of nested into package file. fs.FileInfo implementation.
func (*Tagset_t) Path ¶ added in v1.3.0
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
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
Put appends new tag to tagset. Can be used in chain calls at initialization.
func (*Tagset_t) Set ¶ added in v1.3.0
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
Size returns size of nested into package file. fs.FileInfo implementation.
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) Uint16 ¶ added in v1.3.0
Uint16 is 16-bit unsigned int tag getter. Conversion can be used to get signed 16-bit integers.