buf: github.com/bufbuild/buf/internal/pkg/storage Index | Files | Directories

package storage

import "github.com/bufbuild/buf/internal/pkg/storage"

Package storage implements a simple storage abstraction.

This is meant to abstract filesystem calls, as well as be a wrapper for in-memory or remote storage. It also provides a smaller attack vector as implementations can do verifications as to what is accessed and what is not.


Package Files



var (
    // ErrIncompleteWrite is the error returned if a write is not complete
    ErrIncompleteWrite = errors.New("incomplete write")
    // ErrClosed is the error returned if a bucket or object is already closed.
    ErrClosed = errors.New("already closed")

func IsNotExist Uses

func IsNotExist(err error) bool

IsNotExist returns true for a Error that is for a path not existing.

func NewErrNotExist Uses

func NewErrNotExist(path string) *storagepath.Error

NewErrNotExist returns a new Error for a path not existing.

type BucketInfo Uses

type BucketInfo interface {
    // InMemory returns true if the bucket is in memory.
    InMemory() bool

BucketInfo contains bucket info.

type ObjectInfo Uses

type ObjectInfo interface {
    // Size is the size of the object.
    // For writes, the write size must sum up to this size when closed, otherwise ErrIncompleteWrite is returned.
    // For writes, any write over this size will return io.EOF.
    Size() uint32

ObjectInfo contains object info.

type ReadBucket Uses

type ReadBucket interface {
    // Get gets the path.
    // Returns ErrNotExist if the path does not exist, other error
    // if there is a system error.
    Get(ctx context.Context, path string) (ReadObject, error)
    // Stat gets info in the object.
    // Returns ErrNotExist if the path does not exist, other error
    // if there is a system error.
    Stat(ctx context.Context, path string) (ObjectInfo, error)
    // Walk walks the bucket with the prefix, calling f on each path.
    // Note that foo/barbaz will not be called for foo/bar, but will
    // be called for foo/bar/baz.
    // All paths given to f are normalized and validated.
    // If f returns error, Walk will stop short and return this error.
    // Returns other error on system error.
    Walk(ctx context.Context, prefix string, f func(string) error) error

    Info() BucketInfo

ReadBucket is a simple read-only bucket.

All paths regular files - Buckets do not handle directories. All paths must be relative. All paths are cleaned and ToSlash'ed by each function. Paths must not jump the bucket context, that is after clean, they cannot contain "..".

type ReadBucketCloser Uses

type ReadBucketCloser interface {

ReadBucketCloser is a read-only bucket that must be closed.

type ReadObject Uses

type ReadObject interface {

    Info() ObjectInfo

ReadObject is a read-only object.

It must be closed when done.

type ReadWriteBucket Uses

type ReadWriteBucket interface {

    // Put returns a WriteCloser to write to the path.
    // The path is truncated beforehand.
    // Returns error on system error.
    Put(ctx context.Context, path string, size uint32) (WriteObject, error)

ReadWriteBucket is a simple read/write bucket.

type ReadWriteBucketCloser Uses

type ReadWriteBucketCloser interface {

ReadWriteBucketCloser is a read/write bucket that must be closed.

type WriteObject Uses

type WriteObject interface {

    Info() ObjectInfo

WriteObject is a write-only object.

It must be closed when done.


internal/storagetestingPackage storagetesting implements all testing for the storage packages.
storagegitPackage storagegit implements git utilities.
storagememPackage storagemem implements an in-memory storage Bucket.
storageosPackage storageos implements an os-backed storage Bucket.
storagepathPackage storagepath provides functions similar to filepath.
storageutilPackage storageutil implements storage utilities.

Package storage imports 4 packages (graph) and is imported by 5 packages. Updated 2020-04-07. Refresh now. Tools for package owners.