nvc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package nvc implements a parser for nvc archive files.

The format of an archive is described below. All header values are stored on disk as little endian.

  1. NVC magic bytes (8 bytes)
  2. Number of entries in the archive's table of contents (32-bit little endian unsigned integer)
  3. Table of Contents entries (24 * n bytes, where n is the previously-specified number of entries)

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMagicFound error = errors.New("nvc magic bytes not found")

Functions

This section is empty.

Types

type Archive

type Archive struct {
	Entries    map[Hash]TocEntry // Map of hashes to table of contents entries
	EntryOrder []Hash            // List of entry hashes in the order that they are stored in the archive
	// contains filtered or unexported fields
}

func Parse

func Parse(r io.ReadSeeker) (Archive, error)

Parse reads r and attempts to interpret is as an NVC archive. This function takes ownership of r; it should not be used by the caller after Parse has been called. The returned Archive should not be used when the returned error is non-nil.

func (Archive) File

func (a Archive) File(hash Hash) ([]byte, error)

File returns the data for the file that is reference by hash

type EntryFlags

type EntryFlags uint32

EntryFlags describes how a file is stored on disk

const (
	// EntryFlagNoCompression indicates that the file is stored in the NVC archive uncompressed
	EntryFlagNoCompression EntryFlags = 0
	// EntryFlagZlibCompression indicates that the file is stored in the NVC archive with zlib compression
	EntryFlagZlibCompression EntryFlags = 1
	// EntryFlagEncrypted indicates that the file is encrypted
	EntryFlagEncrypted EntryFlags = 3
)

type Hash

type Hash uint64

Hash is a 64-bit FNV-1a hash

func String2Hash

func String2Hash(s string) Hash

String2Hash returns the 64-bit FNV-1a hash of s

func (Hash) String

func (h Hash) String() string

type TocEntry

type TocEntry struct {
	Hash      Hash       // 64-bit FNV-1a hash of the file's path on disk
	Offset    uint32     // File's offset (in bytes) from the start of the nvc file
	RawLength uint32     // Length (in bytes) of the file after it has been extracted
	Length    uint32     // Length (in bytes) of file as it is stored in the nvc file
	Flags     EntryFlags // Indicates whether file is compressed or encrypted (TODO: determine if this is a bitmask)
}

TocEntry is a file entry in the table of contents.

func (TocEntry) String

func (e TocEntry) String() string

type Writer

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

Writer is an nvc archive writer.

func NewWriter

func NewWriter(w io.WriteSeeker, length uint32) (Writer, error)

NewWriter returns an nvc archive writer that writes to w. length is the number of files that will be placed in the archive. Finalize should be called once all files have been written to the archive (via Create or CreateCompressed).

func (*Writer) Create

func (w *Writer) Create(r io.Reader, hash Hash) (int64, error)

Create reads an archive member file from r and writes it to w.

Create increments w's internal Table of Contents entry counter by 1; it will panic if this counter exceeds the value of "length" that was passed to NewWriter. This function is not thread-safe; only one archive member file can be written to w at a time.

func (*Writer) CreateCompressed

func (w *Writer) CreateCompressed(r io.Reader, hash Hash, level int) (int64, error)

CreateCompressed increments w's internal Table of Contents entry counter by 1; it will panic if this counter exceeds the value of "length" that was passed to NewWriter. This function is not thread-safe; only one archive member file can be written to w at a time.

func (*Writer) Finalize

func (w *Writer) Finalize() error

Finalize writes the nvc header to the start of w. It is an error to call Create after Finalize has been called.

Jump to

Keyboard shortcuts

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