storage

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

package storage defines interfaces for the storage of typst package cache, and retrieving of packages from the package cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentStore

type ContentStore interface {
	View(pkg deps.Dependency) (PackageView, error)
}

ContentStore defines APIs to get a package view from the package store.

type FsPackageStore

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

func NewFsPackageStore

func NewFsPackageStore(cacheDir string) (*FsPackageStore, error)

func (*FsPackageStore) Add

func (f *FsPackageStore) Add(pkg deps.Dependency, archive io.Reader) error

Add implements PackageStore.

func (*FsPackageStore) Has

func (f *FsPackageStore) Has(pkg deps.Dependency) (bool, error)

Has implements PackageStore.

func (*FsPackageStore) List

func (f *FsPackageStore) List(filter func(spec deps.Dependency) bool) ([]deps.Dependency, error)

List implements PackageStore.

func (*FsPackageStore) Path

func (f *FsPackageStore) Path(pkg deps.Dependency) (string, error)

Path implements PackageStore.

func (*FsPackageStore) Remove

func (f *FsPackageStore) Remove(pkg deps.Dependency) error

Remove implements PackageStore.

func (*FsPackageStore) View

View implements ContentStore.

type FsPackageView

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

A package view basd on os file system. Callers must call Close to release the internal root, and package view lock, otherwise Add and Remove of the same package in the package store will be blocked.

func (*FsPackageView) Close

func (v *FsPackageView) Close() error

func (*FsPackageView) Open

func (v *FsPackageView) Open(name string) (fs.File, error)

type PackageStore

type PackageStore interface {
	// Has checks if pkg exists in the cache, returning error if something
	// goes wrong during the check.
	Has(pkg deps.Dependency) (bool, error)

	// Add adds a package to the storage, with package namespace, name and version
	// specified by pkg. The content should be a tar.gz archive reader.
	Add(pkg deps.Dependency, archive io.Reader) error

	// List returns all versioned packages inside the package store. If a filter
	// is provided, it is used to filter out the result, otherwise all results are
	// returned. If the filter returns true, the package is returned, otherwise
	// the package is omitted.
	List(filter func(spec deps.Dependency) bool) ([]deps.Dependency, error)

	// Remove a package from the store. When a specific version is provided, that
	// version is removed, otherwise the entire package versions are removed.
	Remove(pkg deps.Dependency) error

	// Path returns the underlying storage path for pkg.
	Path(pkg deps.Dependency) (string, error)
}

PackageStore defines the main storage APIs for the typst package cache.

type PackageView

type PackageView interface {
	fs.FS
	// Closer is used to release the underlying root handle.
	io.Closer
}

PackageView defines a sandboxed, read-only view of one package. Paths are slash-seperated and relative to the package root, e,g. "typst.toml", "templates/main.typ".

type Store added in v0.14.2

type Store interface {
	PackageStore
	ContentStore
}

Jump to

Keyboard shortcuts

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