storage

package
v0.0.0-...-efd161f Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BOFMark = []byte{
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x23, 0x7E, 0x91, 0x4D, 0x2E, 0xE0, 0x43, 0x1A,
}

BOFMark is the Beginning-Of-File Marker. A magic sequence of bytes written before the metadata and content of every file in the archive.

So, if a part of the archive is partially damaged, the program will be able to recover all intact files.

Functions

func ExistsDir

func ExistsDir(path string) bool

ExistsDir returns true if a directory exists, or false otherwise.

func ExistsFile

func ExistsFile(path string) bool

ExistsFile returns true if a file exists, or false otherwise.

func ExistsPath

func ExistsPath(path string) bool

ExistsPath returns true if a path exists, or false otherwise.

func ReadBOFMark

func ReadBOFMark(rd io.ReadSeeker, pos int64) error

ReadBOFMark attempts to read the Beginning-Of-File Marker from the reader 'rd' at the position specified by 'pos'.

When it succeeds, moves the reader's position to pos+len(BOFMark). When it fails, it attempts to move to 'pos'.

Returns nil if successful, or an error if the marker could not be read.

func ReadUint64

func ReadUint64(rd io.Reader) (uint64, error)

ReadUint64 reads a uint64 number from reader 'rd'.

The number should have been previously written by WriteUint64(). See WriteUint64() for more details how these numbers are stored to conserve space.

func WriteBOFMark

func WriteBOFMark(wr io.Writer) error

WriteBOFMark writes the Beginning-Of-File Marker to writer 'wr'.

func WriteBytes

func WriteBytes(wr io.Writer, data []byte) error

WriteBytes writes the bytes in 'data' to writer 'wr'.

func WriteString

func WriteString(wr io.Writer, s string) error

WriteString writes a string to writer 'wr'.

func WriteUint64

func WriteUint64(wr io.Writer, num uint64) error

WriteUint64 writes a uint64 value to writer 'wr' using the minimum number of bytes.

The written bytes consist of two parts:

* The first byte specifies the number of additional bytes needed to store the unsigned. It can range from 0 (for 0) to 8 bytes for largest numbers.

* The second part contains from 0 to 8 bytes that represent the number.

The function saves space provided most numbers are not large: 0 only needs 1 byte, 0-255 only needs two bytes, etc. But math.MaxUint64 would need 9 bytes instead of 8.

Types

type File

type File struct {
	Path    string
	Size    uint64
	ModTime time.Time
	Hash    [64]byte
	Content []byte
}

File holds file information and content.

func ReadArchivedFile

func ReadArchivedFile(
	rd io.ReadSeeker,
	pos int64,
	loadContent bool,
	enc *security.Encryption,
) (
	*File, error,
)

ReadArchivedFile creates a File by reading and decrypting it from an open archive file (the 'rd' reader) at the specified position.

If 'loadContent' is true, loads the file's contents, otherwise only reads the file's metadata (size, path, etc.)

func ReadFile

func ReadFile(path string) (*File, error)

ReadFile reads a file from the specified path and creates a new File object containing the file's properties and data.

func (*File) SetRelativePath

func (fl *File) SetRelativePath(path string)

SetRelativePath adjusts the file's Path by making it relative to the 'path' parameter.

func (*File) WriteEncryptedContent

func (fl *File) WriteEncryptedContent(
	wr io.Writer,
	enc *security.Encryption,
) error

WriteEncryptedContent writes the file's content to writer 'wr'.

func (*File) WriteEncryptedMetadata

func (fl *File) WriteEncryptedMetadata(
	wr io.Writer,
	enc *security.Encryption,
) error

WriteEncryptedMetadata encrypts and writes file metadata to writer 'wr'. The metadata consists of file size, modified time, hash and path.

Jump to

Keyboard shortcuts

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