archive

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotRegularFile = errors.New("file type is not regular")
)

Functions

func CopyHeader

func CopyHeader(h *tar.Header) *tar.Header

CopyHeader duplicates the given tar.Header, suitable for use in a new tar archive.

Types

type Path

type Path struct {
	*url.URL
}

Path represents a parsed URL to an object in GCS or local file.

func ParseArchiveURL

func ParseArchiveURL(path string) (*Path, error)

ParseArchiveURL parses a gs:// or file:// path of a .tgz archive.

func ParseURL

func ParseURL(path string) (*Path, error)

ParseURL parses a GCS path of any object type.

func (*Path) Bucket

func (p *Path) Bucket() string

Bucket returns the path bucket name.

func (*Path) Dup

func (p *Path) Dup(bucket string) *Path

Dup creates a new Path with an alternate named bucket.

func (*Path) Filename

func (p *Path) Filename() string

Filename returns a filename based on the Path.

func (*Path) Object

func (p *Path) Object() string

Object returns the Object name.

func (*Path) Reader

func (p *Path) Reader(ctx context.Context, client *storage.Client) (*storage.Reader, error)

Reader creates a GCS reader from this Path object. Caller is responsible for calling Close on readers.

func (*Path) Writer

func (p *Path) Writer(ctx context.Context, client *storage.Client) *storage.Writer

Reader creates a GCS writer to this Path object. Caller is responsible for calling Close on writers.

type Source

type Source struct {
	// Path is the original archive URL.
	Path *Path
	// Count is the number of files read from the archive.
	Count int
	// Size is the number of bytes in the archive.
	Size int
	io.Closer
	// contains filtered or unexported fields
}

Source reads from a tar archive from Path containing test files.

func NewFileSource

func NewFileSource(file string) (*Source, error)

NewFileSource creates a new Source for the named file. The file parameter should be a URL, like file:///path/to/filename.tgz

func NewGCSSource

func NewGCSSource(ctx context.Context, client *storage.Client, url string) (*Source, error)

NewGCSSource creates a new Source from the given GCS object. The url parameter should be a GCS URL, like gs://bucket/path/to/filename.tgz

func (*Source) NextFile

func (s *Source) NextFile() (*tar.Header, []byte, error)

NextFile reads the next file from the source, returning the original tar header and file bytes. When the archive is completely read, NextFile returns io.EOF.

type Target

type Target struct {
	// Count is the number of files written to the archive.
	Count int
	// contains filtered or unexported fields
}

A Target represents a single, compressed, tar archive containing files to be uploaded to GCS.

func NewTarget

func NewTarget() *Target

NewTarget creates a new Target for adding files to a compressed tar archive.

func (*Target) AddFile

func (ar *Target) AddFile(h *tar.Header, contents []byte) error

AddFile appends a single file to the Target with the given header and file contents.

func (*Target) Close

func (ar *Target) Close() error

Close closes the Target archive.

func (*Target) Upload

func (ar *Target) Upload(ctx context.Context, client *storage.Client, p *Path) error

Upload writes the completed Target archive contents to the named GCS Path.

Jump to

Keyboard shortcuts

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