modsource

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Overview

getter is a package for downloading files or directories from a variety of protocols.

getter is unique in its ability to download both directories and files. It also detects certain source strings to be protocol-specific URLs. For example, "github.com/c3xdev/c3x/internal/modsource" would turn into a Git URL and use the Git protocol.

Protocols and detectors are extensible.

To get started, see Client.

Index

Constants

This section is empty.

Variables

View Source
var Decompressors = LimitedDecompressors(noFilesLimit, noFileSizeLimit)

Decompressors is the mapping of extension to the Decompressor implementation configured with default settings that will decompress that extension/type.

Note: these decompressors by default do not limit the number of files or the maximum file size created by the decompressed payload.

View Source
var Detectors []Detector

Detectors is the list of detectors that are tried on an invalid URL. This is also the order they're tried (index 0 is first).

View Source
var ErrSymlinkCopy = errors.New("copying of symlinks has been disabled")

ErrSymlinkCopy means that a copy of a symlink was encountered on a request with DisableSymlinks enabled.

View Source
var Getters map[string]Getter

Getters is the mapping of scheme to the Getter implementation that will be used to get a dependency.

Functions

func Copy

func Copy(ctx context.Context, dst io.Writer, src io.Reader) (int64, error)

Copy is a io.Copy cancellable by context

func Detect

func Detect(src string, pwd string, ds []Detector) (string, error)

Detect turns a source string into another source string if it is detected to be of a known pattern.

The third parameter should be the list of detectors to use in the order to try them. If you don't want to configure this, just use the global Detectors variable.

This is safe to be called with an already valid source string: Detect will just return it.

func Get

func Get(ctx context.Context, dst, src string, opts ...ClientOption) error

Get downloads the directory specified by src into the folder specified by dst. If dst already exists, Get will attempt to update it.

src is a URL, whereas dst is always just a file path to a folder. This folder doesn't need to exist. It will be created if it doesn't exist.

func GetAny

func GetAny(ctx context.Context, dst, src string, opts ...ClientOption) error

GetAny downloads a URL into the given destination. Unlike Get or GetFile, both directories and files are supported.

dst must be a directory. If src is a file, it will be downloaded into dst with the basename of the URL. If src is a directory or archive, it will be unpacked directly into dst.

func GetFile

func GetFile(ctx context.Context, dst, src string, opts ...ClientOption) error

GetFile downloads the file specified by src into the path specified by dst.

func LimitedDecompressors

func LimitedDecompressors(filesLimit int, fileSizeLimit int64) map[string]Decompressor

LimitedDecompressors creates the set of Decompressors, but with each compressor configured with the given filesLimit and/or fileSizeLimit where applicable.

func RedactURL

func RedactURL(u *url.URL) string

RedactURL is a port of url.Redacted from the standard library, which is like url.String but replaces any password with "redacted". Only the password in u.URL is redacted. This allows the library to maintain compatibility with go1.14. This port was also extended to redact all "sshkey" from URL query parameter and replace them with "redacted".

func SourceDirSubdir

func SourceDirSubdir(src string) (string, string)

SourceDirSubdir takes a source URL and returns a tuple of the URL without the subdir and the subdir.

ex:

dom.com/path/?q=p               => dom.com/path/?q=p, ""
proto://dom.com/path//*?q=p     => proto://dom.com/path?q=p, "*"
proto://dom.com/path//path2?q=p => proto://dom.com/path?q=p, "path2"

func SubdirGlob

func SubdirGlob(dst, subDir string) (string, error)

SubdirGlob returns the actual subdir with globbing processed.

dst should be a destination directory that is already populated (the download is complete) and subDir should be the set subDir. If subDir is an empty string, this returns an empty string.

The returned path is the full absolute path.

func TestDecompressor

func TestDecompressor(t testing.TB, d Decompressor, cases []TestDecompressCase)

TestDecompressor is a helper function for testing generic decompressors.

func WithInsecure

func WithInsecure() func(*Client) error

WithInsecure allows for a user to avoid checking certificates (not recommended). For example, when connecting on HTTPS where an invalid certificate is presented. User assumes all risk. Not all getters have support for insecure mode yet.

func WithProgress

func WithProgress(pl ProgressTracker) func(*Client) error

WithProgress allows for a user to track the progress of a download. For example by displaying a progress bar with current download. Not all getters have progress support yet.

Types

type BitBucketDetector

type BitBucketDetector struct{}

BitBucketDetector implements Detector to detect BitBucket URLs and turn them into URLs that the Git or Hg Getter can understand.

func (*BitBucketDetector) Detect

func (d *BitBucketDetector) Detect(src, _ string) (string, bool, error)

type Bzip2Decompressor

type Bzip2Decompressor struct {
	// FileSizeLimit limits the size of a decompressed file.
	//
	// The zero value means no limit.
	FileSizeLimit int64
}

Bzip2Decompressor is an implementation of Decompressor that can decompress bz2 files.

func (*Bzip2Decompressor) Decompress

func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type ChecksumError

type ChecksumError struct {
	Hash     hash.Hash
	Actual   []byte
	Expected []byte
	File     string
}

A ChecksumError is returned when a checksum differs

func (*ChecksumError) Error

func (cerr *ChecksumError) Error() string

type Client

type Client struct {

	// Src is the source URL to get.
	//
	// Dst is the path to save the downloaded thing as. If Dir is set to
	// true, then this should be a directory. If the directory doesn't exist,
	// it will be created for you.
	//
	// Pwd is the working directory for detection. If this isn't set, some
	// detection may fail. Client will not default pwd to the current
	// working directory for security reasons.
	Src string
	Dst string
	Pwd string

	// Mode is the method of download the client will use. See ClientMode
	// for documentation.
	Mode ClientMode

	// Umask is used to mask file permissions when storing local files or decompressing
	// an archive
	Umask os.FileMode

	// Detectors is the list of detectors that are tried on the source.
	// If this is nil, then the default Detectors will be used.
	Detectors []Detector

	// Decompressors is the map of decompressors supported by this client.
	// If this is nil, then the default value is the Decompressors global.
	Decompressors map[string]Decompressor

	// Getters is the map of protocols supported by this client. If this
	// is nil, then the default Getters variable will be used.
	Getters map[string]Getter

	// Dir, if true, tells the Client it is downloading a directory (versus
	// a single file). This distinction is necessary since filenames and
	// directory names follow the same format so disambiguating is impossible
	// without knowing ahead of time.
	//
	// WARNING: deprecated. If Mode is set, that will take precedence.
	Dir bool

	// ProgressListener allows to track file downloads.
	// By default a no op progress listener is used.
	ProgressListener ProgressTracker

	// Insecure controls whether a client verifies the server's
	// certificate chain and host name. If Insecure is true, crypto/tls
	// accepts any certificate presented by the server and any host name in that
	// certificate. In this mode, TLS is susceptible to machine-in-the-middle
	// attacks unless custom verification is used. This should be used only for
	// testing or in combination with VerifyConnection or VerifyPeerCertificate.
	// This is identical to tls.Config.InsecureSkipVerify.
	Insecure bool

	// Disable symlinks
	DisableSymlinks bool

	Options []ClientOption
}

Client is a client for downloading things.

Top-level functions such as Get are shortcuts for interacting with a client. Using a client directly allows more fine-grained control over how downloading is done, as well as customizing the protocols supported.

func (*Client) ChecksumFromFile

func (c *Client) ChecksumFromFile(ctx context.Context, checksumFile string, src *url.URL) (*FileChecksum, error)

ChecksumFromFile will return all the FileChecksums found in file

ChecksumFromFile will try to guess the hashing algorithm based on content of checksum file

ChecksumFromFile will only return checksums for files that match file behind src

func (*Client) Configure

func (c *Client) Configure(opts ...ClientOption) error

Configure applies all of the given client options, along with any default behavior including context, decompressors, detectors, and getters used by the client.

func (*Client) Get

func (c *Client) Get(ctx context.Context) error

Get downloads the configured source to the destination.

type ClientMode

type ClientMode uint

ClientMode is the mode that the client operates in.

const (
	ClientModeInvalid ClientMode = iota

	// ClientModeAny downloads anything it can. In this mode, dst must
	// be a directory. If src is a file, it is saved into the directory
	// with the basename of the URL. If src is a directory or archive,
	// it is unpacked directly into dst.
	ClientModeAny

	// ClientModeFile downloads a single file. In this mode, dst must
	// be a file path (doesn't have to exist). src must point to a single
	// file. It is saved as dst.
	ClientModeFile

	// ClientModeDir downloads a directory. In this mode, dst must be
	// a directory path (doesn't have to exist). src must point to an
	// archive or directory (such as in s3).
	ClientModeDir
)

type ClientOption

type ClientOption func(*Client) error

ClientOption is used to configure a client.

func WithDecompressors

func WithDecompressors(decompressors map[string]Decompressor) ClientOption

WithDecompressors specifies which Decompressor are available.

func WithDetectors

func WithDetectors(detectors []Detector) ClientOption

WithDecompressors specifies which compressors are available.

func WithGetters

func WithGetters(getters map[string]Getter) ClientOption

WithGetters specifies which getters are available.

func WithMode

func WithMode(mode ClientMode) ClientOption

WithMode specifies which client mode the getters should operate in.

func WithUmask

func WithUmask(mode os.FileMode) ClientOption

WithUmask specifies how to mask file permissions when storing local files or decompressing an archive.

type Decompressor

type Decompressor interface {
	// Decompress should decompress src to dst. dir specifies whether dst
	// is a directory or single file. src is guaranteed to be a single file
	// that exists. dst is not guaranteed to exist already.
	Decompress(dst, src string, dir bool, umask os.FileMode) error
}

Decompressor defines the interface that must be implemented to add support for decompressing a type.

Important: if you're implementing a decompressor, please use the containsDotDot helper in this file to ensure that files can't be decompressed outside of the specified directory.

type Detector

type Detector interface {
	// Detect will detect whether the string matches a known pattern to
	// turn it into a proper URL.
	Detect(string, string) (string, bool, error)
}

Detector defines the interface that an invalid URL or a URL with a blank scheme is passed through in order to determine if its shorthand for something else well-known.

type FileChecksum

type FileChecksum struct {
	Type     string
	Hash     hash.Hash
	Value    []byte
	Filename string
}

FileChecksum helps verifying the checksum for a file.

type FileDetector

type FileDetector struct{}

FileDetector implements Detector to detect file paths.

func (*FileDetector) Detect

func (d *FileDetector) Detect(src, pwd string) (string, bool, error)

type FileGetter

type FileGetter struct {

	// Copy, if set to true, will copy data instead of using a symlink. If
	// false, attempts to symlink to speed up the operation and to lower the
	// disk space usage. If the symlink fails, may attempt to copy on windows.
	Copy bool
	// contains filtered or unexported fields
}

FileGetter is a Getter implementation that will download a module from a file scheme.

func (*FileGetter) ClientMode

func (g *FileGetter) ClientMode(_ context.Context, u *url.URL) (ClientMode, error)

func (*FileGetter) Get

func (g *FileGetter) Get(ctx context.Context, dst string, u *url.URL) error

func (*FileGetter) GetFile

func (g *FileGetter) GetFile(ctx context.Context, dst string, u *url.URL) error

func (*FileGetter) SetClient

func (g *FileGetter) SetClient(c *Client)

type FolderStorage

type FolderStorage struct {
	// StorageDir is the directory where the modules will be stored.
	StorageDir string
}

FolderStorage is an implementation of the Storage interface that manages modules on the disk.

func (*FolderStorage) Dir

func (s *FolderStorage) Dir(key string) (d string, e bool, err error)

Dir implements Storage.Dir

func (*FolderStorage) Get

func (s *FolderStorage) Get(ctx context.Context, key string, source string, update bool) error

Get implements Storage.Get

type GCSDetector

type GCSDetector struct{}

GCSDetector implements Detector to detect GCS URLs and turn them into URLs that the GCSGetter can understand.

func (*GCSDetector) Detect

func (d *GCSDetector) Detect(src, _ string) (string, bool, error)

type GCSGetter

type GCSGetter struct {

	// FileSizeLimit limits the size of an single
	// decompressed file.
	//
	// The zero value means no limit.
	FileSizeLimit int64
	// contains filtered or unexported fields
}

GCSGetter is a Getter implementation that will download a module from a GCS bucket.

func (*GCSGetter) ClientMode

func (g *GCSGetter) ClientMode(ctx context.Context, u *url.URL) (ClientMode, error)

func (*GCSGetter) Get

func (g *GCSGetter) Get(ctx context.Context, dst string, u *url.URL) error

func (*GCSGetter) GetFile

func (g *GCSGetter) GetFile(ctx context.Context, dst string, u *url.URL) error

func (*GCSGetter) SetClient

func (g *GCSGetter) SetClient(c *Client)

type Getter

type Getter interface {
	// Get downloads the given URL into the given directory. This always
	// assumes that we're updating and gets the latest version that it can.
	//
	// The directory may already exist (if we're updating). If it is in a
	// format that isn't understood, an error should be returned. Get shouldn't
	// simply nuke the directory.
	Get(context.Context, string, *url.URL) error

	// GetFile downloads the give URL into the given path. The URL must
	// reference a single file. If possible, the Getter should check if
	// the remote end contains the same file and no-op this operation.
	GetFile(context.Context, string, *url.URL) error

	// ClientMode returns the mode based on the given URL. This is used to
	// allow clients to let the getters decide which mode to use.
	ClientMode(context.Context, *url.URL) (ClientMode, error)

	// SetClient allows a getter to know it's client
	// in order to access client's Get functions or
	// progress tracking.
	SetClient(*Client)
}

Getter defines the interface that schemes must implement to download things.

type GitDetector

type GitDetector struct{}

GitDetector implements Detector to detect Git SSH URLs such as git@host.com:dir1/dir2 and converts them to proper URLs.

func (*GitDetector) Detect

func (d *GitDetector) Detect(src, _ string) (string, bool, error)

type GitGetter

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

GitGetter is a Getter implementation that will download a module from a git repository.

func (*GitGetter) ClientMode

func (g *GitGetter) ClientMode(_ context.Context, u *url.URL) (ClientMode, error)

func (*GitGetter) Get

func (g *GitGetter) Get(ctx context.Context, dst string, u *url.URL) error

func (*GitGetter) GetFile

func (g *GitGetter) GetFile(ctx context.Context, dst string, u *url.URL) error

GetFile for Git doesn't support updating at this time. It will download the file every time.

func (*GitGetter) SetClient

func (g *GitGetter) SetClient(c *Client)

type GitHubDetector

type GitHubDetector struct{}

GitHubDetector implements Detector to detect GitHub URLs and turn them into URLs that the Git Getter can understand.

func (*GitHubDetector) Detect

func (d *GitHubDetector) Detect(src, _ string) (string, bool, error)

type GitLabDetector

type GitLabDetector struct{}

GitLabDetector implements Detector to detect GitLab URLs and turn them into URLs that the Git Getter can understand.

func (*GitLabDetector) Detect

func (d *GitLabDetector) Detect(src, _ string) (string, bool, error)

type GzipDecompressor

type GzipDecompressor struct {
	// FileSizeLimit limits the size of a decompressed file.
	//
	// The zero value means no limit.
	FileSizeLimit int64
}

GzipDecompressor is an implementation of Decompressor that can decompress gzip files.

func (*GzipDecompressor) Decompress

func (d *GzipDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type HgGetter

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

HgGetter is a Getter implementation that will download a module from a Mercurial repository.

func (*HgGetter) ClientMode

func (g *HgGetter) ClientMode(_ context.Context, _ *url.URL) (ClientMode, error)

func (*HgGetter) Get

func (g *HgGetter) Get(ctx context.Context, dst string, u *url.URL) error

func (*HgGetter) GetFile

func (g *HgGetter) GetFile(ctx context.Context, dst string, u *url.URL) error

GetFile for Hg doesn't support updating at this time. It will download the file every time.

func (*HgGetter) SetClient

func (g *HgGetter) SetClient(c *Client)

type HttpGetter

type HttpGetter struct {

	// Netrc, if true, will lookup and use auth information found
	// in the user's netrc file if available.
	Netrc bool

	// Client is the http.Client to use for Get requests.
	// This defaults to a cleanhttp.DefaultClient if left unset.
	Client *http.Client

	// Header contains optional request header fields that should be included
	// with every HTTP request. Note that the zero value of this field is nil,
	// and as such it needs to be initialized before use, via something like
	// make(http.Header).
	Header http.Header

	// DoNotCheckHeadFirst configures the client to NOT check if the server
	// supports HEAD requests.
	DoNotCheckHeadFirst bool

	// HeadFirstTimeout configures the client to enforce a timeout when
	// the server supports HEAD requests.
	//
	// The zero value means no timeout.
	HeadFirstTimeout time.Duration

	// ReadTimeout configures the client to enforce a timeout when
	// making a request to an HTTP server and reading its response body.
	//
	// The zero value means no timeout.
	ReadTimeout time.Duration

	// MaxBytes limits the number of bytes that will be ready from an HTTP
	// response body returned from a server. The zero value means no limit.
	MaxBytes int64

	// XTerraformGetLimit configures how many times the client with follow
	// the " X-Terraform-Get" header value.
	//
	// The zero value means no limit.
	XTerraformGetLimit int

	// XTerraformGetDisabled disables the client's usage of the "X-Terraform-Get"
	// header value.
	XTerraformGetDisabled bool
	// contains filtered or unexported fields
}

HttpGetter is a Getter implementation that will download from an HTTP endpoint.

For file downloads, HTTP is used directly.

The protocol for downloading a directory from an HTTP endpoint is as follows:

An HTTP GET request is made to the URL with the additional GET parameter "terraform-get=1". This lets you handle that scenario specially if you wish. The response must be a 2xx.

First, a header is looked for "X-Terraform-Get" which should contain a source URL to download. This source must use one of the configured protocols and getters for the client, or "http"/"https" if using the HttpGetter directly.

If the header is not present, then a meta tag is searched for named "terraform-get" and the content should be a source URL.

The source URL, whether from the header or meta tag, must be a fully formed URL. The shorthand syntax of "github.com/foo/bar" or relative paths are not allowed.

func (*HttpGetter) ClientMode

func (g *HttpGetter) ClientMode(_ context.Context, u *url.URL) (ClientMode, error)

func (*HttpGetter) Get

func (g *HttpGetter) Get(ctx context.Context, dst string, u *url.URL) error

func (*HttpGetter) GetFile

func (g *HttpGetter) GetFile(ctx context.Context, dst string, src *url.URL) error

GetFile fetches the file from src and stores it at dst. If the server supports Accept-Range, HttpGetter will attempt a range request. This means it is the caller's responsibility to ensure that an older version of the destination file does not exist, else it will be either falsely identified as being replaced, or corrupted with extra bytes appended.

func (*HttpGetter) SetClient

func (g *HttpGetter) SetClient(c *Client)

type MockGetter

type MockGetter struct {

	// Proxy, if set, will be called after recording the calls below.
	// If it isn't set, then the *Err values will be returned.
	Proxy Getter

	GetCalled bool
	GetDst    string
	GetURL    *url.URL
	GetErr    error

	GetFileCalled bool
	GetFileDst    string
	GetFileURL    *url.URL
	GetFileErr    error
	// contains filtered or unexported fields
}

MockGetter is an implementation of Getter that can be used for tests.

func (*MockGetter) ClientMode

func (g *MockGetter) ClientMode(_ context.Context, u *url.URL) (ClientMode, error)

func (*MockGetter) Get

func (g *MockGetter) Get(ctx context.Context, dst string, u *url.URL) error

func (*MockGetter) GetFile

func (g *MockGetter) GetFile(ctx context.Context, dst string, u *url.URL) error

func (*MockGetter) SetClient

func (g *MockGetter) SetClient(c *Client)

type ProgressTracker

type ProgressTracker interface {
	// TrackProgress should be called when
	// a new object is being downloaded.
	// src is the location the file is
	// downloaded from.
	// currentSize is the current size of
	// the file in case it is a partial
	// download.
	// totalSize is the total size in bytes,
	// size can be zero if the file size
	// is not known.
	// stream is the file being downloaded, every
	// written byte will add up to processed size.
	//
	// TrackProgress returns a ReadCloser that wraps the
	// download in progress ( stream ).
	// When the download is finished, body shall be closed.
	TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser)
}

ProgressTracker allows to track the progress of downloads.

type S3Detector

type S3Detector struct{}

S3Detector implements Detector to detect S3 URLs and turn them into URLs that the S3 getter can understand.

func (*S3Detector) Detect

func (d *S3Detector) Detect(src, _ string) (string, bool, error)

type S3Getter

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

S3Getter is a Getter implementation that will download a module from a S3 bucket.

func (*S3Getter) ClientMode

func (g *S3Getter) ClientMode(ctx context.Context, u *url.URL) (ClientMode, error)

func (*S3Getter) Get

func (g *S3Getter) Get(ctx context.Context, dst string, u *url.URL) error

func (*S3Getter) GetFile

func (g *S3Getter) GetFile(ctx context.Context, dst string, u *url.URL) error

func (*S3Getter) SetClient

func (g *S3Getter) SetClient(c *Client)

type Storage

type Storage interface {
	// Dir returns the directory on local disk where the directory source
	// can be loaded from.
	Dir(string) (string, bool, error)

	// Get will download and optionally update the given directory.
	Get(context.Context, string, string, bool) error
}

Storage is an interface that knows how to lookup downloaded directories as well as download and update directories from their sources into the proper location.

type TarBzip2Decompressor

type TarBzip2Decompressor struct {
	// FileSizeLimit limits the total size of all
	// decompressed files.
	//
	// The zero value means no limit.
	FileSizeLimit int64

	// FilesLimit limits the number of files that are
	// allowed to be decompressed.
	//
	// The zero value means no limit.
	FilesLimit int
}

TarBzip2Decompressor is an implementation of Decompressor that can decompress tar.bz2 files.

func (*TarBzip2Decompressor) Decompress

func (d *TarBzip2Decompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type TarDecompressor

type TarDecompressor struct {
	// FileSizeLimit limits the total size of all
	// decompressed files.
	//
	// The zero value means no limit.
	FileSizeLimit int64

	// FilesLimit limits the number of files that are
	// allowed to be decompressed.
	//
	// The zero value means no limit.
	FilesLimit int
}

TarDecompressor is an implementation of Decompressor that can unpack tar files.

func (*TarDecompressor) Decompress

func (d *TarDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type TarGzipDecompressor

type TarGzipDecompressor struct {
	// FileSizeLimit limits the total size of all
	// decompressed files.
	//
	// The zero value means no limit.
	FileSizeLimit int64

	// FilesLimit limits the number of files that are
	// allowed to be decompressed.
	//
	// The zero value means no limit.
	FilesLimit int
}

TarGzipDecompressor is an implementation of Decompressor that can decompress tar.gzip files.

func (*TarGzipDecompressor) Decompress

func (d *TarGzipDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type TarXzDecompressor

type TarXzDecompressor struct {
	// FileSizeLimit limits the total size of all
	// decompressed files.
	//
	// The zero value means no limit.
	FileSizeLimit int64

	// FilesLimit limits the number of files that are
	// allowed to be decompressed.
	//
	// The zero value means no limit.
	FilesLimit int
}

TarXzDecompressor is an implementation of Decompressor that can decompress tar.xz files.

func (*TarXzDecompressor) Decompress

func (d *TarXzDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type TarZstdDecompressor

type TarZstdDecompressor struct {
	// FileSizeLimit limits the total size of all
	// decompressed files.
	//
	// The zero value means no limit.
	FileSizeLimit int64

	// FilesLimit limits the number of files that are
	// allowed to be decompressed.
	//
	// The zero value means no limit.
	FilesLimit int
}

TarZstdDecompressor is an implementation of Decompressor that can decompress tar.zstd files.

func (*TarZstdDecompressor) Decompress

func (d *TarZstdDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type TestDecompressCase

type TestDecompressCase struct {
	Input   string     // Input is the complete path to the input file
	Dir     bool       // Dir is whether or not we're testing directory mode
	Err     bool       // Err is whether we expect an error or not
	DirList []string   // DirList is the list of files for Dir mode
	FileMD5 string     // FileMD5 is the expected MD5 for a single file
	Mtime   *time.Time // Mtime is the optionally expected mtime for a single file (or all files if in Dir mode)
}

TestDecompressCase is a single test case for testing decompressors

type XzDecompressor

type XzDecompressor struct {
	// FileSizeLimit limits the size of a decompressed file.
	//
	// The zero value means no limit.
	FileSizeLimit int64
}

XzDecompressor is an implementation of Decompressor that can decompress xz files.

func (*XzDecompressor) Decompress

func (d *XzDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type ZipDecompressor

type ZipDecompressor struct {
	// FileSizeLimit limits the total size of all
	// decompressed files.
	//
	// The zero value means no limit.
	FileSizeLimit int64

	// FilesLimit limits the number of files that are
	// allowed to be decompressed.
	//
	// The zero value means no limit.
	FilesLimit int
}

ZipDecompressor is an implementation of Decompressor that can decompress zip files.

func (*ZipDecompressor) Decompress

func (d *ZipDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

type ZstdDecompressor

type ZstdDecompressor struct {
	// FileSizeLimit limits the size of a decompressed file.
	//
	// The zero value means no limit.
	FileSizeLimit int64
}

ZstdDecompressor is an implementation of Decompressor that can decompress .zst files.

func (*ZstdDecompressor) Decompress

func (d *ZstdDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error

Directories

Path Synopsis
helper
url

Jump to

Keyboard shortcuts

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