far

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package far implements Fuchsia archive operations. At this time only archive writing is supported. The specification for the archive format can be found in https://fuchsia.dev/fuchsia-src/concepts/storage/archive_format

Index

Constants

View Source
const DirectoryEntryLen = 4 + 2 + 2 + 8 + 8 + 8

DirectoryEntryLen is the byte size of the DirectoryEntry struct

View Source
const IndexEntryLen = 8 + 8 + 8

IndexEntryLen is the byte size of the IndexEntry struct

View Source
const IndexLen = 8 + 8

IndexLen is the byte size of the Index struct

View Source
const Magic = "\xc8\xbf\x0b\x48\xad\xab\xc5\x11"

Magic is the first bytes of a FAR archive

Variables

This section is empty.

Functions

func IsFAR

func IsFAR(r io.Reader) bool

IsFAR looks for the FAR magic header, returning true if it is found. Only the header is consumed from the given input. If any IO error occurs, false is returned.

func Write

func Write(w io.Writer, inputs map[string]string) error

Write writes a list of files to the given io. The inputs map provides a list of target archive paths mapped to on-disk file paths from which the content should be fetched.

Types

type ChunkType

type ChunkType uint64

ChunkType is a uint64 representing the type of a non-index chunk

const (
	DirChunk      ChunkType = 0x2d2d2d2d2d524944 // "DIR-----"
	DirNamesChunk ChunkType = 0x53454d414e524944 // "DIRNAMES"
)

Various chunk types

type DirectoryEntry

type DirectoryEntry struct {
	NameOffset uint32
	NameLength uint16
	Reserved   uint16
	DataOffset uint64
	DataLength uint64
	Reserved2  uint64
}

DirectoryEntry indexes into the dirnames and contents chunks to provide access to file names and file contents respectively.

type EntryReader

type EntryReader struct {
	// Offset of this entry from the start of the archive
	Offset uint64
	// Length of this entry in the archive
	Length uint64

	Source io.ReaderAt
}

EntryReader allows reading the contents of an archive entry, file or directory.

func (*EntryReader) ReadAt

func (e *EntryReader) ReadAt(buf []byte, offset int64) (int, error)

type ErrInvalidArchive

type ErrInvalidArchive string

ErrInvalidArchive is returned from reads when the archive is not of the expected format or is corrupted.

func (ErrInvalidArchive) Error

func (e ErrInvalidArchive) Error() string

type Index

type Index struct {
	// Magic bytes must equal the Magic constant
	Magic [8]byte
	// Length of all index entries in bytes
	Length uint64
}

Index is the first chunk of an archive

type IndexEntry

type IndexEntry struct {
	// Type of the chunk
	Type ChunkType
	// Offset from the start of the archive
	Offset uint64
	// Length of the chunk
	Length uint64
}

IndexEntry identifies the type and position of a chunk in the archive

type PathData

type PathData []byte

PathData is a concatenated list of names of files that makes up the unpadded portion of a dirnames chunk.

type Reader

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

Reader wraps an io.ReaderAt providing access to FAR contents from that io. It caches the directory and path information after it is read, and provides io.Readers for files contained in the archive.

func NewReader

func NewReader(s io.ReaderAt) (*Reader, error)

NewReader wraps the given io.ReaderAt and returns a struct that provides indexed access to the FAR contents.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the underlying reader source, if it implements io.Closer

func (*Reader) GetSize

func (r *Reader) GetSize(path string) uint64

func (*Reader) List

func (r *Reader) List() []string

List provides the list of all file names in the archive

func (*Reader) Open

func (r *Reader) Open(path string) (*EntryReader, error)

Open finds the file in the archive and returns an EntryReader that can read the contents

func (*Reader) ReadFile

func (r *Reader) ReadFile(path string) ([]byte, error)

ReadFile reads a whole file out of the archive

Jump to

Keyboard shortcuts

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