Top.Mail.Ru
package fs — KubFly SDK for Go

KubFly SDK for Go / bucket/fs

package fs

import "kubfly.io/sdk/bucket/fs"

Package fs is the file system as a bucket: a directory is the bucket, a key is a path under it — the io.kubfly.sdk.bucket.fs package of the Java SDK. Linking it in registers the kind FS (KUBFLY_BUCKET_KIND=FS, KUBFLY_BUCKET_ROOT).

Constants

const Temporary = ".bucket-tmp"

Temporary is the directory of temporary files under the root; no key starts with it.

Types

type Bucket

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

Bucket is a directory as a bucket: a key is a path under the directory, its levels — directories. A write goes to a temporary file in .bucket-tmp under the root and is renamed in place atomically, so a reader sees the old object or the new one; a removal also removes the directories it leaves empty, as a prefix of S3 disappears with its last object. A key may not be both an object and a level of another key (S3 allows it; the formats of KubFly never do). A listing walks the directories at every iteration and sorts by key.

func (*Bucket) Builder

func (s *Bucket) Builder() bucket.Builder

Builder are the settings of this bucket.

func (*Bucket) Bytes

func (s *Bucket) Bytes(ctx context.Context, key string) (util.Option[bucket.Stored[[]byte]], error)

Bytes are the bytes of a file.

func (*Bucket) BytesRange

func (s *Bucket) BytesRange(ctx context.Context, key string, offset int64,
	length int) (util.Option[bucket.Stored[[]byte]], error)

BytesRange is a range of the bytes of a file.

func (*Bucket) Close

func (s *Bucket) Close() error

Close closes nothing: no file stays open between calls.

func (*Bucket) Create

func (s *Bucket) Create(ctx context.Context, key string, data []byte) (bool, error)

Create writes a file only if there is none with the key: a hard link of the written temporary file, which fails if the file exists — one step; where links are not supported, a check and a rename.

func (*Bucket) Delete

func (s *Bucket) Delete(ctx context.Context, key string) error

Delete removes a file and the levels it leaves empty.

func (*Bucket) Find

func (s *Bucket) Find(ctx context.Context, key string) (util.Option[bucket.Obj], error)

Find are the fields of a file.

func (*Bucket) List

func (s *Bucket) List(ctx context.Context, prefix string) iter.Seq2[bucket.Obj, error]

List are the files of a prefix, by key.

func (*Bucket) ListFilter

func (s *Bucket) ListFilter(ctx context.Context, prefix string, filter bucket.Filter) iter.Seq2[bucket.Obj, error]

ListFilter are the files of a prefix that match a filter, by key; every iteration walks the directories anew.

func (*Bucket) Put

func (s *Bucket) Put(ctx context.Context, key string, data []byte) error

Put writes a file atomically: a temporary file, then a rename in place.

func (*Bucket) PutStream

func (s *Bucket) PutStream(ctx context.Context, key string, data func() (io.ReadCloser, error), length int64) error

PutStream writes a file from a stream atomically: one stream is taken.

func (*Bucket) String

func (s *Bucket) String() string

String is the text form.

func (*Bucket) Time

func (s *Bucket) Time() util.Option[bucket.BucketTime]

Time is no time: a file system has no clock of its own.

type Builder

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

Builder is the file system as a bucket (the kind FS): the directory and the prefix of a stand.

func NewBuilder

func NewBuilder() Builder

NewBuilder is the kind FS without a directory.

func (Builder) Build

func (b Builder) Build() (bucket.Bucket, error)

Build opens the directory, creating it if missing; under the prefix of the stand, if any.

func (Builder) Env

func (b Builder) Env(envPrefix string, env map[string]string) (bucket.Builder, error)

Env is this builder filled from <ENV_PREFIX>_BUCKET_ROOT and <ENV_PREFIX>_BUCKET_PREFIX.

func (Builder) Kind

func (b Builder) Kind() string

Name is the name of the kind: FS.

func (Builder) Prefix

func (b Builder) Prefix() string

Prefix is the prefix of the stand, "" — none.

func (Builder) Root

func (b Builder) Root() util.Option[string]

Root is the directory; None until it is set.

func (Builder) String

func (b Builder) String() string

String is the text form.

func (Builder) WithPrefix

func (b Builder) WithPrefix(prefix string) bucket.Builder

WithPrefix is this builder with the prefix of a stand ("" — none); checked by Build.

func (Builder) WithRoot

func (b Builder) WithRoot(root string) Builder

WithRoot is this builder with a directory.