arc

package module
v0.0.0-...-9ac8841 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: CC0-1.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBlocksize = 8 * (1 << 10) // 8 KiB

DefaultBlocksize is the default size, in bytes, of a file chunk within the container.

Variables

View Source
var (
	// ErrWriterClosed is returned when Writer is used after closed.
	ErrWriterClosed = errors.New("writer closed")

	// ErrEmptyPassword is returned when a file have encryption enabled, but
	// no password was provided.
	ErrEmptyPassword = errors.New("encrypted marked file with no password provided")

	// ErrNotEncrypted is returned when a file isn't marked for encryption, but
	// a password was provided.
	ErrNotEncrypted = errors.New("password provided for unencrypted container")

	// ErrNoFilename is returned when is tried to create a file with no name.
	ErrNoFilename = errors.New("attempt to create file with no name")

	// ErrnoFileSelected is returned when reading a [Reader] with no file
	// selected previously.
	ErrNoFileSelected = errors.New("no file selected for reading")

	// ErrWrongPassword is returned when providing the wrong password to an
	// container with encrypted files.
	ErrWrongPassword = errors.New("wrong password")

	ErrPadding = errors.New("corrupted filename pad")
)

Functions

This section is empty.

Types

type Header struct {
	// Id of the file in the container.
	//
	// The Id is only relevent for the [Reader],
	// and thereby ignored by the [Writer].
	Id int

	// Name of the file.
	Name string

	// Size, in bytes, of the file, outside the container.
	//
	// As the [Header.Id] field, this field is too ignored
	// by the [Writer].
	Size int

	// ModTime is the last time the file was modified,
	// in UTC location.
	ModTime time.Time

	// Compression indicates what level of compression
	// is applied to the file.
	//
	// The default value (0) indicates that no compression
	// is applied.
	//
	// When reading the file this field must only be checked
	// against the zero value (0).
	Compression zstd.EncoderLevel

	// Encryption indicates if file is encrypted or not.
	Encryption bool
}

Header represents a file in the arc file.

type Reader

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

func NewReader

func NewReader(databasePath string, password []byte) (*Reader, error)

func (*Reader) Files

func (reader *Reader) Files() (files map[string]*Header, err error)

func (*Reader) IsEncrypted

func (reader *Reader) IsEncrypted() bool

func (*Reader) Open

func (reader *Reader) Open(id int, transaction bool) error

func (*Reader) Read

func (reader *Reader) Read(p []byte) (int, error)

func (*Reader) ReadToFile

func (reader *Reader) ReadToFile(id int, filepath string) (err error)

func (*Reader) SetPassword

func (reader *Reader) SetPassword(password []byte) error

type Writer

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

Writer implements a arc container writer. Writer.WriteHeader initiates a new file with the providaded Header, and then the Writer can be used as an io.Writer.

func NewWriter

func NewWriter(databasePath string, blocksize int, password []byte) (*Writer, error)

NewWriter creates a new Writer and a container file with name databasePath.

func (*Writer) Close

func (writer *Writer) Close() error

Close closes the container and flushes any remaining data of the current file to the container. Subsequently calls to Close or any other method will yield ErrWriterClosed

func (*Writer) Write

func (writer *Writer) Write(p []byte) (int, error)

Write writes the current file in the container, implementing the io.Writer interface.

func (*Writer) WriteFile

func (writer *Writer) WriteFile(header *Header, filepath string) (err error)

WriteFile looks for a filepath file and add to container accordingly to header. The file is added all in one transaction.

func (*Writer) WriteHeader

func (writer *Writer) WriteHeader(header *Header, transaction bool) error

WriteHeader prepares the Writer for writing the file described by header.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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