exturl

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 27 Imported by: 32

README

exturl

License Go Reference Go Report Card

URLs for Go on steroids.

Simply put, it allows you to get a Go Reader from a wide variety of URL types, including specific entries in archives using a URL structure inspired by Java's JarURLConnection.

Features

Especially powerful is the ability to refer to entries in remote archives, e.g. a zip file over http. Where possible exturl will stream the data (e.g. remote tarballs), but if filesystem access is required (for remote zip, git repository clones, and Docker images) it will download them to a temporary local location. The use of a shared context allows for optimization, e.g. a remote zip file will not be downloaded again if it was already downloaded in the context. Examples:

tar:http://mysite.org/cloud.tar.gz\!main.yaml
git:https://github.com/tliron/puccini.git!examples/openstack/hello-world.yaml

Another powerful feature is support for relative URLs using common filesystem paths, including usage of .. and .. All URL types support this: file URLs, local and remote zip URLs, etc. Use url.Relative().

You can also ensure that a URL is valid (remote location is available) before attempting to read from it (which may trigger a download) or passing it to other parts of your program. To do so, use NewValidURL() instead of NewURL(). NewValidURL() also supports relative URLs tested against a list of potential origins. Compare with how the PATH environment variable is used by the OS to find commands.

Also supported are URLs for in-memory data using a special internal: scheme. This allows you to have a unified API for accessing data, whether it's available externally or created internally by your program.

Example

import (
    "context"
    "github.com/tliron/exturl"
)

func ReadAll(url string) ([]byte, error) {
    urlContext := exturl.NewContext()
    defer urlContext.Release()

    url_ := urlContext.NewURL(url)
    if reader, err := url_.Open(context.TODO()); err == nil {
        defer reader.Close()
        return io.ReadAll(reader)
    } else {
        return nil, err
    }
}

Supported URL Types

file:

A path to the local filesystem. This is the default URL type if no schema is provided.

The URL must begin with two slashes. If a hostname is present before the path it will be ignored, so this:

file://localhost/the/path

is equivalent to this:

file:///the/path

Relative paths are supported, but only when no scheme is provided. In other words, the file: scheme requires absolute paths. The consequence is that file: URLs usually begin with three slashes because absolute paths also begin with a slash.

When compiled for Windows the URL path will be converted to a Windows path. So this:

file:///C:/Windows/win.ini

will be treated as this path:

C:\Windows\win.ini

Note that for security reasons relative file URLs are not tested against the current working directory (pwd) by default. This is unlike OS services, such as Go's os.Open(). If you do want to support the working directory then call NewWorkingDirFileURL() and add it explicitly to the origins of NewValidURL().

It is often desirable to accept input that is either a URL or a file path. For this use case NewAnyOrFileURL() and NewValidAnyOrFileURL() are provided. If the argument is not a parsable URL it will be treated as a file path and a *FileURL will be returned.

These functions introduce a rare edge case for Windows. If there happens to be a drive that has the same name as a supported URL scheme (e.g. "http") then callers would have to provide a full file URL, otherwise it will be parsed as a URL of that scheme. E.g. instead of:

http:\Dir\file

you must use:

file:///http:/Dir/file
http: and https:

Uses standard Go access libraries (net/http).

tar:

Entries in tarballs. .tar and .tar.gz (or .tgz) are supported. Examples:

tar:/local/path/cloud.tar.gz\!path/to/main.yaml
tar:http://mysite.org/cloud.tar.gz\!path/to/main.yaml

Note that tarballs are serial containers optimized for streaming. That means that when accessed the entries will be skipped until our entry is found and then subsequent entries will be ignored. This means that when accessing tarballs over the network the tarball does not have to be downloaded, unlike with zip (see below).

Gzip decompression uses klauspost's pgzip library.

zip:

Entries in zip files. Example:

zip:http://mysite.org/cloud.tar.gz\!path/to/main.yaml

Note that zip files require random access and thus must be on the local file system. Consequently for remote zips the entire archive must be downloaded in order to access one entry. For optimization, exturl will make sure to download it only once per context.

Uses klauspost's compress library.

git:

Files in git repositories. Example:

git:https://github.com/tliron/puccini.git!examples/openstack/hello-world.yaml

You can specify a reference (tag, branch tip, or commit hash) in the URL fragment, e.g.:

git:https://github.com/tliron/puccini.git#main!examples/openstack/hello-world.yaml

Because we are only interested in reading files, exturl will optimize by performing shallow clones of only the requested reference.

Uses go-git.

docker:

Images on OCI/Docker registries. The URL structure is docker://HOSTNAME/[NAMESPACE/]REPOSITORY[:TAG]. The tag will default to "latest". Example:

docker://docker.io/tliron/prudence:latest

The url.Open() API will decode the first layer (a .tar.gz) it finds in the image. The intended use case is using OCI registries to store arbitrary data. In the future we may support more elaborate use cases.

Uses go-containerregistry.

internal:

Internal URLs can ne stored globally so that all contexts will be able to access them.

Supported APIs for global internal URLs are RegisterInternalURL() (which will fail if the URL has already been registered), DeregisterInternalURL(), UpdateInternalURL() (which will always succeed), ReadToInternalURL(), ReadToInternalURLFromStdin().

It is also possible to create ad-hoc internal URLs using NewInternalURL() and then SetContent(). These are not stored globally.

Content can be []byte or an implementation of the InternalURLProvider interface. Other types will be converted to string and then to []byte.

Mock URLs

These are intended to be used for testing. They must be created explicitly via NewMockURL() and can use any scheme. They are not created by NewURL().

Documentation

Index

Constants

View Source
const PathSeparator = string(filepath.Separator)

Variables

View Source
var TARBALL_ARCHIVE_FORMATS = []string{"tar", "tar.gz"}

Functions

func DeleteTemporaryDir

func DeleteTemporaryDir(path string) error

func DeleteTemporaryFile

func DeleteTemporaryFile(path string) error

func DeregisterInternalURL

func DeregisterInternalURL(path string)

func Download

func Download(context contextpkg.Context, url URL, temporaryPathPattern string) (*os.File, error)

func DownloadTo

func DownloadTo(context contextpkg.Context, url URL, path string) error

func GetFormat

func GetFormat(path string) string

func GetPath

func GetPath(url URL) (string, error)

func GetTemporaryPathPattern added in v0.2.4

func GetTemporaryPathPattern(key string) string

func IsNotFound

func IsNotFound(err error) bool

func IsNotImplemented added in v0.2.8

func IsNotImplemented(err error) bool

func IsValidTarballArchiveFormat

func IsValidTarballArchiveFormat(archiveFormat string) bool

func OpenFirstTarballInTarball added in v0.2.2

func OpenFirstTarballInTarball(reader io.Reader) (io.Reader, error)

func ReadBytes

func ReadBytes(context contextpkg.Context, url URL) ([]byte, error)

func ReadString

func ReadString(context contextpkg.Context, url URL) (string, error)

func ReadToInternalURLsFromFS added in v0.2.7

func ReadToInternalURLsFromFS(context contextpkg.Context, fs fspkg.FS, root string, process func(path string) (string, bool)) error

func RegisterInternalURL

func RegisterInternalURL(path string, content any) error

`content` can be []byte or an InternalURLProvider. Other types will be converted to string and then to []byte.

func Size

func Size(context contextpkg.Context, url URL) (int64, error)

func ToNetURL

func ToNetURL(url URL) (*neturlpkg.URL, error)

func URLPathToFilePath added in v0.2.1

func URLPathToFilePath(path string) string

func UpdateInternalURL

func UpdateInternalURL(path string, content any)

Types

type Context

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

func NewContext

func NewContext() *Context

func (*Context) GetCredentials

func (self *Context) GetCredentials(host string) *Credentials

Not thread-safe

func (*Context) GetHTTPRoundTripper

func (self *Context) GetHTTPRoundTripper(host string) http.RoundTripper

Not thread-safe

func (*Context) GetLocalPath

func (self *Context) GetLocalPath(context contextpkg.Context, url URL) (string, error)

Will download the file to the local temporary directory if not already locally available

func (*Context) GetMapping

func (self *Context) GetMapping(fromUrl string) (string, bool)

func (*Context) Map

func (self *Context) Map(fromUrl string, toUrl string)

Set mapping to empty string to delete it

func (*Context) NewAnyOrFileURL added in v0.3.1

func (self *Context) NewAnyOrFileURL(urlOrPath string) URL

Parses the argument as *either* an absolute URL *or* a file path.

In essence attempts to parse the URL via [NewURL] and if that fails treats the URL as a file path and returns a *FileURL.

To support relative URLs, see [NewValidAnyOrFileURL].

On Windows note that if there happens to be a drive that has the same name as a supported URL scheme (e.g. "http") then callers would have to provide a full file URL, e.g. instead of "http:\Dir\file" provide "file:///http:/Dir/file", otherwise it will be parsed as a URL of that scheme.

func (*Context) NewDockerURL added in v0.2.0

func (self *Context) NewDockerURL(neturl *neturlpkg.URL) *DockerURL

func (*Context) NewFileURL added in v0.2.0

func (self *Context) NewFileURL(filePath string) *FileURL

Note that the argument is treated as an OS file path (using backslashes on Windows).

Directories *must* be suffixed with an OS path separator.

func (*Context) NewGitURL added in v0.2.0

func (self *Context) NewGitURL(path string, repositoryUrl string) *GitURL

func (*Context) NewInternalURL added in v0.2.0

func (self *Context) NewInternalURL(path string) *InternalURL

func (*Context) NewMockURL added in v0.2.9

func (self *Context) NewMockURL(scheme string, path string, content any) *MockURL

func (*Context) NewNetworkURL added in v0.2.0

func (self *Context) NewNetworkURL(neturl *neturlpkg.URL) *NetworkURL

func (*Context) NewURL added in v0.2.0

func (self *Context) NewURL(url string) (URL, error)

Parses the argument as an absolute URL.

To support relative URLs, see [NewValidURL].

If you are expecting either a URL *or* a file path, consider [NewAnyOrFileURL].

func (*Context) NewValidAnyOrFileURL added in v0.3.1

func (self *Context) NewValidAnyOrFileURL(context contextpkg.Context, urlOrPath string, origins []URL) (URL, error)

Parses the argument as an absolute URL *or* an absolute file path *or* a relative path. Relative paths support ".." and ".", with the returned URL path being absolute.

The returned URL is "valid", meaning that during this call it was possible to call Open on it. Of course this can't guarantee that future calls to Open will succeed.

Relative URLs are tested against the origins argument in order. The first valid URL will be returned and the remaining origins will be ignored.

func (*Context) NewValidDockerURL added in v0.2.0

func (self *Context) NewValidDockerURL(neturl *neturlpkg.URL) (*DockerURL, error)

func (*Context) NewValidFileURL added in v0.2.0

func (self *Context) NewValidFileURL(filePath string) (*FileURL, error)

Note that the argument is treated as an OS file path (using backslashes on Windows).

If the path is a directory, it will automatically be suffixed with an OS path separator if it doesn't already have one.

func (*Context) NewValidGitURL added in v0.2.0

func (self *Context) NewValidGitURL(path string, repositoryUrl string) (*GitURL, error)

func (*Context) NewValidInternalURL added in v0.2.0

func (self *Context) NewValidInternalURL(path string) (*InternalURL, error)

func (*Context) NewValidNetworkURL added in v0.2.0

func (self *Context) NewValidNetworkURL(neturl *neturlpkg.URL) (*NetworkURL, error)

func (*Context) NewValidURL added in v0.2.0

func (self *Context) NewValidURL(context contextpkg.Context, urlOrPath string, origins []URL) (URL, error)

Parses the argument as *either* an absolute URL *or* a relative path. Relative paths support ".." and ".", with the returned URL path being absolute.

The returned URL is "valid", meaning that during this call it was possible to call Open on it. Of course this can't guarantee that future calls to Open will succeed.

Relative URLs are tested against the origins argument in order. The first valid URL will be returned and the remaining origins will be ignored.

If you are expecting either a URL *or* a file path, consider [NewValidAnyOrFileURL].

func (*Context) NewWorkingDirFileURL added in v0.3.0

func (self *Context) NewWorkingDirFileURL() (*FileURL, error)

func (*Context) OpenFile

func (self *Context) OpenFile(context contextpkg.Context, url URL) (*os.File, error)

func (*Context) ParseGitURL added in v0.2.0

func (self *Context) ParseGitURL(url string) (*GitURL, error)

func (*Context) ParseTarballURL added in v0.2.0

func (self *Context) ParseTarballURL(url string) (*TarballURL, error)

func (*Context) ParseValidGitURL added in v0.2.0

func (self *Context) ParseValidGitURL(url string) (*GitURL, error)

func (*Context) ParseValidTarballURL added in v0.2.0

func (self *Context) ParseValidTarballURL(context contextpkg.Context, url string) (*TarballURL, error)

func (*Context) ParseValidZipURL added in v0.2.0

func (self *Context) ParseValidZipURL(context contextpkg.Context, url string) (*ZipURL, error)

func (*Context) ParseZipURL added in v0.2.0

func (self *Context) ParseZipURL(url string) (*ZipURL, error)

func (*Context) ReadToInternalURL added in v0.2.0

func (self *Context) ReadToInternalURL(path string, reader io.Reader) (*InternalURL, error)

func (*Context) ReadToInternalURLFromStdin added in v0.2.0

func (self *Context) ReadToInternalURLFromStdin(context contextpkg.Context, format string) (*InternalURL, error)

func (*Context) Release

func (self *Context) Release() error

func (*Context) SetCredentials

func (self *Context) SetCredentials(host string, username string, password string, token string)

Not thread-safe

func (*Context) SetHTTPRoundTripper

func (self *Context) SetHTTPRoundTripper(host string, httpRoundTripper http.RoundTripper)

Not thread-safe

type Credentials

type Credentials struct {
	Username string
	Password string
	Token    string
}

type DockerURL

type DockerURL struct {
	URL *neturlpkg.URL
	// contains filtered or unexported fields
}

func (*DockerURL) Context

func (self *DockerURL) Context() *Context

URL interface

func (*DockerURL) Format

func (self *DockerURL) Format() string

URL interface

func (*DockerURL) Key

func (self *DockerURL) Key() string

URL interface

func (*DockerURL) Open

func (self *DockerURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*DockerURL) Origin

func (self *DockerURL) Origin() URL

URL interface

func (*DockerURL) Relative

func (self *DockerURL) Relative(path string) URL

URL interface

func (*DockerURL) RemoteOptions

func (self *DockerURL) RemoteOptions(context contextpkg.Context) []remote.Option

func (*DockerURL) String

func (self *DockerURL) String() string

URL interface fmt.Stringer interface

func (*DockerURL) WriteFirstLayer added in v0.2.2

func (self *DockerURL) WriteFirstLayer(context contextpkg.Context, writer io.Writer) error

func (*DockerURL) WriteTarball

func (self *DockerURL) WriteTarball(context contextpkg.Context, writer io.Writer) error

type FileURL

type FileURL struct {
	Path string
	// contains filtered or unexported fields
}

func (*FileURL) Context

func (self *FileURL) Context() *Context

URL interface

func (*FileURL) Format

func (self *FileURL) Format() string

URL interface

func (*FileURL) Key

func (self *FileURL) Key() string

URL interface

func (*FileURL) NewValidRelativeFileURL added in v0.2.0

func (self *FileURL) NewValidRelativeFileURL(filePath string) (*FileURL, error)

Note that the argument is treated as an OS file path (using backslashes on Windows).

func (*FileURL) Open

func (self *FileURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*FileURL) Origin

func (self *FileURL) Origin() URL

URL interface

func (*FileURL) Relative

func (self *FileURL) Relative(path string) URL

Note that the argument can be a URL-type path *or* an OS file path (using backslashes on Windows).

Directories *must* be suffixed with an OS path separator.

URL interface

func (*FileURL) String

func (self *FileURL) String() string

URL interface fmt.Stringer interface

type FirstTarballInTarballDecoder added in v0.2.2

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

func NewFirstTarballInTarballDecoder added in v0.2.2

func NewFirstTarballInTarballDecoder(reader io.Reader) *FirstTarballInTarballDecoder

func (*FirstTarballInTarballDecoder) Decode added in v0.2.2

func (self *FirstTarballInTarballDecoder) Decode() io.Reader

func (*FirstTarballInTarballDecoder) Drain added in v0.2.2

func (self *FirstTarballInTarballDecoder) Drain()

type GitURL

type GitURL struct {
	Path          string
	RepositoryURL string
	Reference     string
	Username      string
	Password      string
	// contains filtered or unexported fields
}

func (*GitURL) Context

func (self *GitURL) Context() *Context

URL interface

func (*GitURL) Format

func (self *GitURL) Format() string

URL interface

func (*GitURL) Key

func (self *GitURL) Key() string

URL interface

func (*GitURL) NewValidRelativeGitURL added in v0.2.0

func (self *GitURL) NewValidRelativeGitURL(path string) (*GitURL, error)

func (*GitURL) Open

func (self *GitURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*GitURL) OpenRepository

func (self *GitURL) OpenRepository() (*git.Repository, error)

func (*GitURL) Origin

func (self *GitURL) Origin() URL

URL interface

func (*GitURL) Relative

func (self *GitURL) Relative(path string) URL

URL interface

func (*GitURL) String

func (self *GitURL) String() string

URL interface fmt.Stringer interface

type InternalURL

type InternalURL struct {
	Path    string
	Content any // []byte or InternalURLProvider
	// contains filtered or unexported fields
}

func (*InternalURL) Context

func (self *InternalURL) Context() *Context

URL interface

func (*InternalURL) Format

func (self *InternalURL) Format() string

URL interface

func (*InternalURL) Key

func (self *InternalURL) Key() string

URL interface

func (*InternalURL) NewValidRelativeInternalURL added in v0.2.0

func (self *InternalURL) NewValidRelativeInternalURL(path string) (*InternalURL, error)

func (*InternalURL) Open

func (self *InternalURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*InternalURL) Origin

func (self *InternalURL) Origin() URL

URL interface

func (*InternalURL) Relative

func (self *InternalURL) Relative(path string) URL

URL interface

func (*InternalURL) SetContent

func (self *InternalURL) SetContent(content any)

func (*InternalURL) String

func (self *InternalURL) String() string

URL interface fmt.Stringer interface

type InternalURLProvider added in v0.2.4

type InternalURLProvider interface {
	OpenPath(context contextpkg.Context, path string) (io.ReadCloser, error)
}

type MockURL added in v0.2.9

type MockURL struct {
	Scheme  string
	Path    string
	Content any // []byte or InternalURLProvider
	// contains filtered or unexported fields
}

func (*MockURL) Context added in v0.2.9

func (self *MockURL) Context() *Context

URL interface

func (*MockURL) Format added in v0.2.9

func (self *MockURL) Format() string

URL interface

func (*MockURL) Key added in v0.2.9

func (self *MockURL) Key() string

URL interface

func (*MockURL) Open added in v0.2.9

func (self *MockURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*MockURL) Origin added in v0.2.9

func (self *MockURL) Origin() URL

URL interface

func (*MockURL) Relative added in v0.2.9

func (self *MockURL) Relative(path string) URL

URL interface

func (*MockURL) String added in v0.2.9

func (self *MockURL) String() string

URL interface fmt.Stringer interface

type NetworkURL

type NetworkURL struct {
	URL *neturlpkg.URL
	// contains filtered or unexported fields
}

func (*NetworkURL) Context

func (self *NetworkURL) Context() *Context

URL interface

func (*NetworkURL) Format

func (self *NetworkURL) Format() string

URL interface

func (*NetworkURL) Key

func (self *NetworkURL) Key() string

URL interface

func (*NetworkURL) NewValidRelativeNetworkURL added in v0.2.0

func (self *NetworkURL) NewValidRelativeNetworkURL(path string) (*NetworkURL, error)

func (*NetworkURL) Open

func (self *NetworkURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*NetworkURL) Origin

func (self *NetworkURL) Origin() URL

URL interface

func (*NetworkURL) Relative

func (self *NetworkURL) Relative(path string) URL

URL interface

func (*NetworkURL) String

func (self *NetworkURL) String() string

URL interface fmt.Stringer interface

type NotFound

type NotFound struct {
	Message string
}

func NewNotFound

func NewNotFound(message string) *NotFound

func NewNotFoundf

func NewNotFoundf(format string, arg ...any) *NotFound

func (*NotFound) Error

func (self *NotFound) Error() string

error interface

type NotImplemented added in v0.2.8

type NotImplemented struct {
	Message string
}

func NewNotImplemented added in v0.2.8

func NewNotImplemented(message string) *NotImplemented

func NewNotImplementedf added in v0.2.8

func NewNotImplementedf(format string, arg ...any) *NotImplemented

func (*NotImplemented) Error added in v0.2.8

func (self *NotImplemented) Error() string

error interface

type TarballEntryReader

type TarballEntryReader struct {
	TarballReader *TarballReader
}

func NewTarballEntryReader

func NewTarballEntryReader(tarballReader *TarballReader) *TarballEntryReader

func (*TarballEntryReader) Close

func (self *TarballEntryReader) Close() error

io.Closer interface

func (*TarballEntryReader) Read

func (self *TarballEntryReader) Read(p []byte) (n int, err error)

io.Reader interface

type TarballReader

type TarballReader struct {
	TarReader         *tar.Reader
	ArchiveReader     io.ReadCloser
	CompressionReader io.ReadCloser
}

func NewTarballReader

func NewTarballReader(reader *tar.Reader, archiveReader io.ReadCloser, compressionReader io.ReadCloser) *TarballReader

func OpenTarballFromFile

func OpenTarballFromFile(file *os.File) (*TarballReader, error)

func (*TarballReader) Close

func (self *TarballReader) Close() error

io.Closer interface

func (*TarballReader) Has

func (self *TarballReader) Has(path string) (bool, error)

func (*TarballReader) Iterate

func (self *TarballReader) Iterate(f func(*tar.Header) bool) error

func (*TarballReader) Open

func (self *TarballReader) Open(path string) (*TarballEntryReader, error)

type TarballURL

type TarballURL struct {
	Path          string
	ArchiveURL    URL
	ArchiveFormat string
}

func NewTarballURL

func NewTarballURL(path string, archiveUrl URL, archiveFormat string) *TarballURL

func NewValidTarballURL

func NewValidTarballURL(context contextpkg.Context, path string, archiveUrl URL, archiveFormat string) (*TarballURL, error)

func (*TarballURL) Context

func (self *TarballURL) Context() *Context

URL interface

func (*TarballURL) Format

func (self *TarballURL) Format() string

URL interface

func (*TarballURL) Key

func (self *TarballURL) Key() string

URL interface

func (*TarballURL) NewValidRelativeTarballURL added in v0.2.0

func (self *TarballURL) NewValidRelativeTarballURL(context contextpkg.Context, path string) (*TarballURL, error)

func (*TarballURL) Open

func (self *TarballURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*TarballURL) OpenArchive

func (self *TarballURL) OpenArchive(context contextpkg.Context) (*TarballReader, error)

func (*TarballURL) Origin

func (self *TarballURL) Origin() URL

URL interface

func (*TarballURL) Relative

func (self *TarballURL) Relative(path string) URL

URL interface

func (*TarballURL) String

func (self *TarballURL) String() string

URL interface fmt.Stringer interface

type URL

type URL interface {
	// Returns a string representation of the URL that can be used by [NewURL] to
	// recreate this URL.
	String() string

	// Format of the URL content's default representation.
	//
	// Should return "yaml", "json", "xml", etc., or an empty string if the format
	// is unknown.
	Format() string

	// Returns the equivalent of a "base directory" for the URL.
	//
	// The origin can be used in two ways:
	//
	// 1. You can call Relative on it to get a sibling URL to this one (relative to
	//    the same "base directory").
	// 2. You can use it in the origins list argument of [NewValidURL] for the same
	//    purpose.
	//
	// Note that the origin might not be a valid URL in itself, e.g. you might not
	// be able to call Open on it.
	Origin() URL

	// Parses the argument as a path relative to this URL. That means this this
	// URL is treated as a "directory".
	//
	// Returns an absolute URL.
	Relative(path string) URL

	// Returns a string that uniquely identifies this URL.
	//
	// Useful as map keys.
	Key() string

	// Opens the URL for reading.
	//
	// It is the caller's responsibility to Close the reader.
	Open(context contextpkg.Context) (io.ReadCloser, error)

	// The context used to create this URL.
	Context() *Context
}

type ZipEntryReader

type ZipEntryReader struct {
	EntryReader io.ReadCloser
	ZipReader   *ZipReader
}

func NewZipEntryReader

func NewZipEntryReader(entryReader io.ReadCloser, zipReader *ZipReader) *ZipEntryReader

func (*ZipEntryReader) Close

func (self *ZipEntryReader) Close() error

io.Closer interface

func (*ZipEntryReader) Read

func (self *ZipEntryReader) Read(p []byte) (n int, err error)

io.Reader interface

type ZipReader

type ZipReader struct {
	ZipReader *zip.Reader
	File      *os.File
}

func NewZipReader

func NewZipReader(reader *zip.Reader, file *os.File) *ZipReader

func OpenZipFromFile

func OpenZipFromFile(file *os.File) (*ZipReader, error)

func (*ZipReader) Close

func (self *ZipReader) Close() error

io.Closer interface

func (*ZipReader) Has

func (self *ZipReader) Has(path string) bool

func (*ZipReader) Iterate

func (self *ZipReader) Iterate(f func(*zip.File) bool)

func (*ZipReader) Open

func (self *ZipReader) Open(path string) (*ZipEntryReader, error)

type ZipURL

type ZipURL struct {
	Path       string
	ArchiveURL URL
}

func NewValidZipURL

func NewValidZipURL(context contextpkg.Context, path string, archiveUrl URL) (*ZipURL, error)

func NewZipURL

func NewZipURL(path string, archiveUrl URL) *ZipURL

func (*ZipURL) Context

func (self *ZipURL) Context() *Context

URL interface

func (*ZipURL) Format

func (self *ZipURL) Format() string

URL interface

func (*ZipURL) Key

func (self *ZipURL) Key() string

URL interface

func (*ZipURL) NewValidRelativeZipURL added in v0.2.0

func (self *ZipURL) NewValidRelativeZipURL(context contextpkg.Context, path string) (*ZipURL, error)

func (*ZipURL) Open

func (self *ZipURL) Open(context contextpkg.Context) (io.ReadCloser, error)

URL interface

func (*ZipURL) OpenArchive

func (self *ZipURL) OpenArchive(context contextpkg.Context) (*ZipReader, error)

func (*ZipURL) Origin

func (self *ZipURL) Origin() URL

URL interface

func (*ZipURL) Relative

func (self *ZipURL) Relative(path string) URL

URL interface

func (*ZipURL) String

func (self *ZipURL) String() string

URL interface fmt.Stringer interface

Jump to

Keyboard shortcuts

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