archive

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package archive writes reproducible tar.gz archives: for a given build of sealift, the same entries always give the same bytes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteTarGz

func WriteTarGz(w io.Writer, root string, entries []Entry) error

WriteTarGz writes a gzip-compressed tar holding root/ and every entry below it, sorted by name. Timestamps are the Unix epoch, owners are 0, files get mode 0644 and the root directory 0755. Entries open one at a time.

Example
package main

import (
	"archive/tar"
	"bytes"
	"compress/gzip"
	"fmt"
	"io"
	"strings"

	"github.com/MorganKryze/sealift/archive"
)

func main() {
	key := "import-secret"
	entries := []archive.Entry{{
		Name: "signature.key",
		Size: int64(len(key)),
		Open: func() (io.ReadCloser, error) { return io.NopCloser(strings.NewReader(key)), nil },
	}}

	var buf bytes.Buffer
	if err := archive.WriteTarGz(&buf, "out", entries); err != nil {
		panic(err)
	}

	gz, _ := gzip.NewReader(&buf)
	tr := tar.NewReader(gz)
	for h, err := tr.Next(); err == nil; h, err = tr.Next() {
		fmt.Println(h.Name)
	}
}
Output:
out/
out/signature.key

Types

type Entry

type Entry struct {
	Name string // path below the root directory, such as "express-4.21.2.tgz"
	Size int64
	Open func() (io.ReadCloser, error)
}

Entry is one file of an archive.

Jump to

Keyboard shortcuts

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