vaar

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 18 Imported by: 0

README

🐳 Vaar 📦

Vaala archive is a tar archive tool & library optimized for lots of small files.

Written in Golang, vaar performs operations in parallel & fully utilizes the POSIX APIs to reduce filesystem overheads.

Vaar is capable of tar creation & extraction. It works only on Linux & macOS.

Vaar is in beta. Some bugs are still out there 🙏

Install

Go 1.16+ is required to compile vaar.

As a command

go install github.com/moycat/vaar/cmd/vaar@latest

As a library

import "github.com/moycat/vaar"

CLI Usage

Suppose you have $GOPATH/bin in your PATH.

The common usage to create a tarball is:

vaar create [-c <algorithm>] [-l <level>] [-r <read_ahead>] <tarball> <file ...>

Arguments:

  • -c <algorithm>: Compression algorithm, lz4 or gzip. No compression by default.
  • -l <level>: Compression level, fastest, fast, default, good or best.
  • -r <read_ahead>: Read ahead size, the maximum number of files to be walked and stated ahead. 512 by default.

Examples:

  • Create a tarball with LZ4 compression: vaar c -c lz4 archive.tar.lz4 seagrass kombu
  • Create a tarball with a large read ahead size: vaar c -r 4096 archive.tar shrimps

The common usage to extract a tarball is:

vaar extract [-c <algorithm>] [-d <target>] [-s <buffer_threshold>] [-t <thread>] [-r <read_ahead>] <tarball>

Arguments:

  • -c <algorithm>: Compression algorithm, lz4 or gzip. No compression by default.
  • -d <target>: Extraction target path. . by default.
  • -s <buffer_threshold>: The size threshold for a file to be buffered in KiB. 512 by default.
  • -t <thread>: The number of buffered extraction thread. 4 by default.
  • -r <read_ahead>: Read ahead size, the maximum number of files to be extracted ahead. 512 by default.

Examples:

  • Extract a LZ4-compressed tarball to /tmp: vaar x -c lz4 -d /tmp archive.tar.lz4
  • Extract a tarball with high concurrency: vaar x -s 4096 -t 32 -r 2048 archive.tar

Appendix

Vaal means whale in Estonian, with Vaala being its genitive form.

Gigantic baleen whales like blue whales eat a large volume of tiny fish and shrimp with extremely high efficiency, by swallowing and filtering tons of water every time they open their mouths.

 ________
< Yummy! >
 --------
    \
     \
      \
                    ##        .
              ## ## ##       ==
           ## ## ## ##      ===
       /""""""""""""""""___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
       \______ o          __/
        \    \        __/
          \____\______/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInapplicableOption   = errors.New("option not inapplicable")
	ErrUnknownValue         = errors.New("value is unknown")
	ErrUnsupportedAlgorithm = errors.New("algorithm unsupported")
)

Functions

func Resolve

func Resolve(r io.Reader, targetPath string, options ...Option) error

Resolve takes a tarball (optionally compressed) from r and extracts it to targetPath with options. The leading slashes of the files are trimmed and path traversal is forbidden.

func Walk

func Walk(path string, walkFunc WalkFunc) error

Walk is a walking function similar to filepath.Walk, but differs in these aspects:

  1. It takes WalkFunc instead of filepath.WalkFunc.
  2. The passed-in path must be a directory.
  3. The error that occurred during walking is directly returned, without passing to WalkFunc.
  4. Lots of magic targeting *nix systems. See the comments for details.

Types

type Algorithm

type Algorithm uint8

Algorithm is the compression algorithm.

const (
	NoAlgorithm Algorithm = iota
	GzipAlgorithm
	LZ4Algorithm
)

func (Algorithm) String

func (c Algorithm) String() string

type Composer

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

Composer is a tarball creation context.

func NewComposer

func NewComposer(w io.Writer, options ...Option) (*Composer, error)

NewComposer creates a Composer with options, writing the tarball to w.

func (*Composer) Add

func (c *Composer) Add(path, base string) error

Add adds a path to the tarball. The path argument is the root path of files being added. If it's a file, only the file is added. The paths of all files are trimmed from the prefix filepath.Dir(path). The base argument is prepended to the paths of all files using filepath.Join. In other words, if you call Add("/a/b/c", "d/e"), all files in /a/b/c are added as d/e/c/... including /a/b/c itself.

func (*Composer) Close

func (c *Composer) Close() error

Close completes the tarball creation. It must be called to flush the buffered bytes.

func (*Composer) TarWriter

func (c *Composer) TarWriter() *tar.Writer

TarWriter returns the underlying tar.Writer. It's for manual operations like adding files only. It mustn't be closed.

type Entry added in v0.0.3

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

Entry represents a file, used in WalkFunc, specialized for tar headers.

func Stat added in v0.0.3

func Stat(path string) (*Entry, error)

Stat stats a file and returns an Entry.

func StatAt added in v0.0.3

func StatAt(dirFd int, name string) (*Entry, error)

StatAt stats a file in an opened directory and returns an Entry.

func (*Entry) Group added in v0.0.3

func (e *Entry) Group() string

func (*Entry) GroupID added in v0.0.3

func (e *Entry) GroupID() uint32

func (*Entry) IsDir added in v0.0.3

func (e *Entry) IsDir() bool

func (*Entry) Linkname added in v0.0.3

func (e *Entry) Linkname() string

func (*Entry) ModTime added in v0.0.3

func (e *Entry) ModTime() time.Time

func (*Entry) Mode added in v0.0.3

func (e *Entry) Mode() os.FileMode

func (*Entry) Name added in v0.0.3

func (e *Entry) Name() string

func (*Entry) Owner added in v0.0.3

func (e *Entry) Owner() string

func (*Entry) OwnerID added in v0.0.3

func (e *Entry) OwnerID() uint32

func (*Entry) Size added in v0.0.3

func (e *Entry) Size() int64

func (*Entry) Sys added in v0.0.3

func (e *Entry) Sys() interface{}

type Level

type Level uint8

Level is the compression level.

const (
	FastestLevel Level = iota
	FastLevel
	DefaultLevel
	GoodLevel
	BestLevel
)

func (Level) String

func (l Level) String() string

type Option

type Option func(i private) error

func WithCompression

func WithCompression(algorithm Algorithm) Option

WithCompression provides the compression algorithm of tar creation and extraction.

func WithLevel

func WithLevel(level Level) Option

WithLevel provides the compression level during tar creation.

func WithReadAhead

func WithReadAhead(n int) Option

WithReadAhead specifies the maximum number of files to be read ahead.

func WithThread

func WithThread(n int) Option

WithThread specifies the worker number during extraction.

func WithThreshold

func WithThreshold(size int64) Option

WithThreshold specifies the threshold size in bytes of buffered files during extraction.

type Resolver

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

Resolver is the context used when a tarball is being extracted. It shouldn't be used directly. Use Resolve instead.

type WalkFunc

type WalkFunc func(path string, entry *Entry, r io.ReadCloser) error

WalkFunc is the type of the function called by Walk to visit each file or directory. The path argument is the absolute path of the current file. The linkName argument is the link target if this file is a symlink, otherwise empty. The entry argument is an Entry struct about this file. The r argument is the reader of this file, if it's a regular one. It must be closed if it's not nil.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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