go.bigb.es/cacher/internal/archive

go.bigb.es/cacher @ v0.2.2 — 333189a2 11 days ago

import "go.bigb.es/cacher/internal/archive"

Overview

Package archive streams a directory through tar+zstd (and back).

Compression level is fixed at zstd level 3 — same as the existing shell (`zstd -T0 -3`). The encoder is wrapped around an io.Writer (typically an S3 multipart Uploader's PipeWriter), so the whole pipeline stays streaming end-to-end with no on-disk tempfile.

Functions

f func DecodeDir

src
func DecodeDir(r io.Reader, dest string) error

DecodeDir extracts a tar.zst stream from r into dest. dest must exist. Any entry whose normalized path escapes dest is rejected.

Read-only entries are the normal case, not an exotic one: the Go module cache is 0555 directories and 0444 files throughout. So directories are created writable and their recorded mode is applied at the very end, and files are written writable and chmod'ed after the copy. Restoring the archived mode as we go would lock the extraction out of the tree it is still filling in.

f func EncodeDir

src
func EncodeDir(w io.Writer, root string) error

EncodeDir walks root in sorted relative-path order and writes a tar.zst stream into w. Symlinks are preserved (stored as tar typelink), devices/sockets/fifos are skipped.

Source files