sardata

package
v0.0.0-...-1b96e9a Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package sardata implements IO routines for reading and writing various chunks of the SARchive format, including checksums, blocks (table of contents and archive data), and the 'magic' bytes.

Index

Constants

View Source
const Magic = "SAR"

Magic is the magic bytes which appear at the beginning of a sarchive.

View Source
const Version byte = 1

Version is the version of the sarchive format.

Variables

This section is empty.

Functions

func BlockReader

func BlockReader(r io.Reader) (io.ReadCloser, error)

BlockReader expects to read a compressed block from r. If it finds one and knows the compression scheme of the block, it will return a ReadCloser which can be used to read the decompressed data from the block.

func BlockWriter

func BlockWriter(w io.Writer, scheme CompressionScheme, level int) (io.WriteCloser, error)

BlockWriter returns a writer that will compress the data given to it. When the returned writer is closed, a BlockHeader and the compressed data will be written to `w`.

This means that the compressed data is unfortunately buffered in memory so that the length of the compressed data can be calculated to put into the header.

func ReadMagic

func ReadMagic(r io.Reader) (version byte, err error)

ReadMagic reads magic from the reader and checks that it's equal to SAR, and ensures that the file version is <= Version.

func ReadTOC

func ReadTOC(r io.Reader) (ret *toc.TOC, err error)

ReadTOC parsses a compressed table of contents from the given reader.

func WriteMagic

func WriteMagic(w io.Writer) error

WriteMagic writes SAR+VERSION to the writer.

func WriteTOC

func WriteTOC(w io.Writer, t *toc.TOC, scheme CompressionScheme, level int) (err error)

WriteTOC writes a compressed table of contents to the given writer.

Types

type BlockHeader

type BlockHeader struct {
	// Length is the number of compressed bytes compose the block, after the end
	// of this header.
	Length uint64

	// Compression indicates the compression decoder scheme that should be used
	// for the block.
	Compression CompressionScheme
}

BlockHeader is used as the prefix to a block.

func (*BlockHeader) Read

func (b *BlockHeader) Read(r io.Reader) (err error)

func (BlockHeader) Write

func (b BlockHeader) Write(w io.Writer) error

type ChecksumScheme

type ChecksumScheme byte

ChecksumScheme are the various checksum types known to the sarchive format.

const (
	ChecksumSHA2_256 ChecksumScheme = iota + 1
	ChecksumSHA2_512
	ChecksumBLAKE2s
	ChecksumBLAKE2b
	ChecksumSHA3_256
	ChecksumSHA3_512

	// Bypasses ALL checksum verification.
	ChecksumNULL ChecksumScheme = 255
)

These are the available checksum algorithms implemented for sarchives.

func ChecksumReader

func ChecksumReader(r readSeekCloser) (ret io.ReadCloser, c ChecksumScheme, err error)

ChecksumReader returns a ReadCloser which will verify the trailing checksum of the stream contained by readSeekCloser. It assumes the beginning of the checksum range is the current position of the readSeekCloser.

The checksum verification will happen when the returned Reader is Close()'d.

func ParseTrailer

func ParseTrailer(r readSeekCloser) (c ChecksumScheme, h hash.Hash, nominalEnd int64, nominalChecksum []byte, err error)

ParseTrailer seeks to the end of r, parses the checksum trailer, and returns the pertinent details.

Note that nominalEnd is an offset from the beginning of the FILE (not the current position of r!), as defined by io.Seeker.

func (ChecksumScheme) Hash

func (c ChecksumScheme) Hash() hash.Hash

Hash gets the Hash interface associated with this scheme.

func (ChecksumScheme) String

func (i ChecksumScheme) String() string

func (ChecksumScheme) Valid

func (c ChecksumScheme) Valid() error

Valid returns nil iff the ChecksumScheme is valid.

func (ChecksumScheme) Writer

Writer converts the provided WriteCloser into a new WriteCloser which will write a checksum footer when it is Close()'d.

type CompressionScheme

type CompressionScheme byte

CompressionScheme indicates the type of compression used in a block, as indicated by that block's BlockHeader.

const (
	CompressionNone CompressionScheme = iota + 1
	CompressionFlate
)

These are the currently supported compressions schemes.

TODO(iannucci): add zstd or brotli as support becomes available.

func (CompressionScheme) Reader

func (c CompressionScheme) Reader(r io.Reader) (io.ReadCloser, error)

Reader returns a new decompressing reader for the given scheme.

func (CompressionScheme) Valid

func (c CompressionScheme) Valid() error

Valid returns a nil err iff this CompressionScheme is valid.

func (CompressionScheme) Writer

func (c CompressionScheme) Writer(w io.Writer, level int) (io.WriteCloser, error)

Writer returns a new compressing writer for the given scheme.

type ErrMismatchedChecksum

type ErrMismatchedChecksum struct {
	Scheme  ChecksumScheme
	Nominal []byte
	Actual  []byte
}

ErrMismatchedChecksum is returned from ChecksumReader if the checksum doesn't match up.

func (*ErrMismatchedChecksum) Error

func (e *ErrMismatchedChecksum) Error() string

Directories

Path Synopsis
Package toc defines the Table of Contents format for SARchives (as proto).
Package toc defines the Table of Contents format for SARchives (as proto).

Jump to

Keyboard shortcuts

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