seektar

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 14 Imported by: 2

README

seektar GoDoc

Dynamically generated tarballs that support seeking. This can be used from a server to generate downloads for entire directories, while supporting Byte-Range requests.

Example

Here's an example of how to use seektar:

package main

import "github.com/unixpickle/seektar"

func main() {
    tarResult, _ := seektar.Tar("/path/to/directory", "directory")
    tarFile, _ := tarResult.Open()
    defer tarFile.Close()
    // tarFile is an io.Reader, io.Seeker, and io.Closer.
    // It dynamically generates tar data.
}

Documentation

Overview

Package seektar dynamically generates tarballs in a deterministic way that allows seeking. This can be used on servers to provide downloads for an entire directory, while still supporting Byte-Range HTTP requests.

Example:

tarResult, _ := seektar.Tar("/path/to/directory", "directory")
tarFile, _ := tarResult.Open()
defer tarFile.Close()
// tarFile is an io.Reader, io.Seeker, and io.Closer.
// It dynamically generates tar data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agg

type Agg []Piece

An Agg is a Piece that combines other Pieces.

func Tar

func Tar(dirPath, prefix string) (Agg, error)

Tar generates a tarball as a Piece.

If prefix is specified, then it is used as a directory name for the tarred content. Otherwise, the tarred content is stored relative to the root of the archive.

The result is deterministic, provided that the contents of the directory do not change.

func TarFile

func TarFile(info os.FileInfo, path, name string) (Agg, error)

TarFile generates a tarball containing a single file.

The name argument specifies the name to give the file within the archive. It should use the '/' path separator.

func TarHTTP

func TarHTTP(vfs http.FileSystem, dirPath, prefix string) (agg Agg, err error)

TarHTTP is like Tar, but for an http.FileSystem.

func TarHTTPFile

func TarHTTPFile(vfs http.FileSystem, info fs.FileInfo, path, name string) (Agg, error)

TarHTTPFile generates a tarball containing a single file in an http.FileSystem.

func (Agg) HashID

func (a Agg) HashID() []byte

func (Agg) Open

func (a Agg) Open() (ReadSeekCloser, error)

func (Agg) Size

func (a Agg) Size() int64

type BytePiece

type BytePiece []byte

A BytePiece is a Piece of pre-defined data.

func (BytePiece) HashID

func (b BytePiece) HashID() []byte

func (BytePiece) Open

func (b BytePiece) Open() (ReadSeekCloser, error)

func (BytePiece) Size

func (b BytePiece) Size() int64

type FilePiece

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

A FilePiece is a Piece that is stored in a file.

func NewFilePiece

func NewFilePiece(path string) (*FilePiece, error)

NewFilePiece creates a FilePiece for a file on disk.

func (*FilePiece) HashID

func (f *FilePiece) HashID() []byte

func (*FilePiece) Open

func (f *FilePiece) Open() (ReadSeekCloser, error)

func (*FilePiece) Size

func (f *FilePiece) Size() int64

type HTTPFilePiece

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

An HTTPFilePiece is a Piece that is stored in a file in an http.FileSsytem.

func NewHTTPFilePiece

func NewHTTPFilePiece(path string, fs http.FileSystem) (*HTTPFilePiece, error)

NewHTTPFilePiece creates an HTTPFilePiece for a file on an http.FileSystem.

func (*HTTPFilePiece) HashID

func (f *HTTPFilePiece) HashID() []byte

func (*HTTPFilePiece) Open

func (f *HTTPFilePiece) Open() (ReadSeekCloser, error)

func (*HTTPFilePiece) Size

func (f *HTTPFilePiece) Size() int64

type Piece

type Piece interface {
	Size() int64
	HashID() []byte
	Open() (ReadSeekCloser, error)
}

A Piece represents a piece of a tarball.

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Closer
	io.ReadSeeker
}

type TarTypeFlag

type TarTypeFlag byte
const (
	NormalFile TarTypeFlag = '0'
	Directory  TarTypeFlag = '5'
	Symlink    TarTypeFlag = '2'
)

Jump to

Keyboard shortcuts

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