uplink

package module
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: Apache-2.0 Imports: 29 Imported by: 97

README

Go library for Storj V3 Network.

Go Report Card Go Doc Beta

Storj is building a decentralized cloud storage network. Check out our white paper for more info!


Storj is an S3-compatible platform and suite of decentralized applications that allows you to store data in a secure and decentralized manner. Your files are encrypted, broken into little pieces and stored in a global decentralized network of computers. Luckily, we also support allowing you (and only you) to retrieve those files!

License

This library is distributed under the Apache v2 license.

Support

If you have any questions or suggestions please reach out to us on our community forum or email us at support@tardigrade.io.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBucketAlreadyExists = errs.Class("bucket already exists")

ErrBucketAlreadyExists is returned when the bucket already exists during creation.

View Source
var ErrBucketNameInvalid = errs.Class("bucket name invalid")

ErrBucketNameInvalid is returned when the bucket name is invalid.

View Source
var ErrBucketNotEmpty = errs.Class("bucket not empty")

ErrBucketNotEmpty is returned when the bucket is not empty during deletion.

View Source
var ErrBucketNotFound = errs.Class("bucket not found")

ErrBucketNotFound is returned when the bucket is not found.

View Source
var ErrObjectKeyInvalid = errs.Class("object key invalid")

ErrObjectKeyInvalid is returned when the object key is invalid.

View Source
var ErrObjectNotFound = errs.Class("object not found")

ErrObjectNotFound is returned when the object is not found.

View Source
var ErrUploadDone = errs.Class("upload done")

ErrUploadDone is returned when either Abort or Commit has already been called.

View Source
var Error = errs.Class("uplink")

Error is default error class for uplink.

Functions

This section is empty.

Types

type Access

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

Access contains everything to access a project and specific buckets.

func ParseAccess

func ParseAccess(access string) (*Access, error)

ParseAccess parses access string.

func RequestAccessWithPassphrase

func RequestAccessWithPassphrase(ctx context.Context, satelliteAddress, apiKey, passphrase string) (*Access, error)

RequestAccessWithPassphrase requests satellite for a new access using a passhprase.

func (*Access) Serialize

func (access *Access) Serialize() (string, error)

Serialize serializes access such that it can be used with ParseAccess.

func (*Access) Share

func (access *Access) Share(permission Permission, prefixes ...SharePrefix) (*Access, error)

Share creates new Access with specific permission. Permission will be applied to prefixes when defined.

type Bucket

type Bucket struct {
	Name    string
	Created time.Time
}

Bucket contains information about the bucket.

type BucketIterator

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

BucketIterator is an iterator over a collection of buckets.

func (*BucketIterator) Err

func (buckets *BucketIterator) Err() error

Err returns error, if one happened during iteration.

func (*BucketIterator) Item

func (buckets *BucketIterator) Item() *Bucket

Item returns the current bucket in the iterator.

func (*BucketIterator) Next

func (buckets *BucketIterator) Next() bool

Next prepares next Bucket for reading. It returns false if the end of the iteration is reached and there are no more buckets, or if there is an error.

type Config

type Config struct {
	UserAgent string

	// DialTimeout defines how long client should wait for establishing
	// a connection to peers.
	DialTimeout time.Duration
}

Config defines configuration for using uplink library.

func (Config) OpenProject

func (config Config) OpenProject(ctx context.Context, access *Access) (project *Project, err error)

OpenProject opens a project with the specific access.

func (Config) RequestAccessWithPassphrase

func (config Config) RequestAccessWithPassphrase(ctx context.Context, satelliteAddress, apiKey, passphrase string) (*Access, error)

RequestAccessWithPassphrase requests satellite for a new access using a passphrase.

type CustomMetadata

type CustomMetadata map[string]string

CustomMetadata contains custom user metadata about the object.

The keys and values in custom metadata are expected to be valid UTF-8.

When choosing a custom key for your application start it with a prefix "app:key", as an example application named "Image Board" might use a key "image-board:title".

func (CustomMetadata) Clone

func (meta CustomMetadata) Clone() CustomMetadata

Clone makes a deep clone.

func (CustomMetadata) Verify

func (meta CustomMetadata) Verify() error

Verify verifies whether CustomMetadata contains only "utf-8".

type Download

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

Download is a download from Storj Network.

func (*Download) Close

func (download *Download) Close() error

Close closes the reader of the download.

func (*Download) Info

func (download *Download) Info() *Object

Info returns the last information about the object.

func (*Download) Read

func (download *Download) Read(data []byte) (n int, err error)

Read downloads up to len(p) bytes into p from the object's data stream. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.

type DownloadOptions

type DownloadOptions struct {
	Offset int64
	// When Length is negative it will read until the end of the blob.
	Length int64
}

DownloadOptions contains additional options for downloading.

type ListBucketsOptions

type ListBucketsOptions struct {
	// Cursor sets the starting position of the iterator. The first item listed will be the one after the cursor.
	Cursor string
}

ListBucketsOptions defines bucket listing options.

type ListObjectsOptions

type ListObjectsOptions struct {
	// Prefix allows to filter objects by a key prefix. If not empty, it must end with slash.
	Prefix string
	// Cursor sets the starting position of the iterator. The first item listed will be the one after the cursor.
	Cursor string
	// Recursive iterates the objects without collapsing prefixes.
	Recursive bool

	// System includes SystemMetadata in the results.
	System bool
	// Custom includes CustomMetadata in the results.
	Custom bool
}

ListObjectsOptions defines object listing options.

type Object

type Object struct {
	Key string
	// IsPrefix indicates whether the Key is a prefix for other objects.
	IsPrefix bool

	System SystemMetadata
	Custom CustomMetadata
}

Object contains information about an object.

type ObjectIterator

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

ObjectIterator is an iterator over a collection of objects or prefixes.

func (*ObjectIterator) Err

func (objects *ObjectIterator) Err() error

Err returns error, if one happened during iteration.

func (*ObjectIterator) Item

func (objects *ObjectIterator) Item() *Object

Item returns the current object in the iterator.

func (*ObjectIterator) Next

func (objects *ObjectIterator) Next() bool

Next prepares next Object for reading. It returns false if the end of the iteration is reached and there are no more objects, or if there is an error.

type Permission

type Permission struct {
	// AllowDownaload gives permission to download the object's content. It
	// allows getting object metadata, but it does not allow listing buckets.
	AllowDownload bool
	// AllowUpload gives permission to create buckets and upload new objects.
	// It does not allow overwriting existing objects unless AllowDelete is
	// granted too.
	AllowUpload bool
	// AllowList gives permission to list buckets. It allows getting object
	// metadata, but it does not allow downloading the object's content.
	AllowList bool
	// AllowDelete gives permission to delete buckets and objects. Unless
	// either AllowDownload or AllowList is granted too, no object metadata and
	// no error info will be returned for deleted objects.
	AllowDelete bool
	// NotBefore if set should be always before NotAfter.
	NotBefore time.Time
	// NotAfter if set should be always after NotBefore.
	NotAfter time.Time
}

Permission defines what actions can be used to share.

func FullPermission

func FullPermission() Permission

FullPermission returns permission that allows all actions.

func ReadOnlyPermission

func ReadOnlyPermission() Permission

ReadOnlyPermission returns permission that allows reading and listing.

func WriteOnlyPermission

func WriteOnlyPermission() Permission

WriteOnlyPermission returns permission that allows writing and deleting.

type Project

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

Project provides access to managing buckets and objects.

func OpenProject

func OpenProject(ctx context.Context, access *Access) (*Project, error)

OpenProject opens a project with the specific access.

func (*Project) Close

func (project *Project) Close() error

Close closes the project and all associated resources.

func (*Project) CreateBucket

func (project *Project) CreateBucket(ctx context.Context, bucket string) (created *Bucket, err error)

CreateBucket creates a new bucket.

When bucket already exists it returns a valid Bucket and ErrBucketExists.

func (*Project) DeleteBucket

func (project *Project) DeleteBucket(ctx context.Context, bucket string) (deleted *Bucket, err error)

DeleteBucket deletes a bucket.

When bucket is not empty it returns ErrBucketNotEmpty.

func (*Project) DeleteObject

func (project *Project) DeleteObject(ctx context.Context, bucket, key string) (deleted *Object, err error)

DeleteObject deletes the object at the specific key.

func (*Project) DownloadObject

func (project *Project) DownloadObject(ctx context.Context, bucket, key string, options *DownloadOptions) (download *Download, err error)

DownloadObject starts a download from the specific key.

func (*Project) EnsureBucket

func (project *Project) EnsureBucket(ctx context.Context, bucket string) (ensured *Bucket, err error)

EnsureBucket ensures that a bucket exists or creates a new one.

When bucket already exists it returns a valid Bucket and no error.

func (*Project) ListBuckets

func (project *Project) ListBuckets(ctx context.Context, options *ListBucketsOptions) *BucketIterator

ListBuckets returns an iterator over the buckets.

func (*Project) ListObjects

func (project *Project) ListObjects(ctx context.Context, bucket string, options *ListObjectsOptions) *ObjectIterator

ListObjects returns an iterator over the objects.

func (*Project) StatBucket

func (project *Project) StatBucket(ctx context.Context, bucket string) (info *Bucket, err error)

StatBucket returns information about a bucket.

func (*Project) StatObject

func (project *Project) StatObject(ctx context.Context, bucket, key string) (info *Object, err error)

StatObject returns information about an object at the specific key.

func (*Project) UploadObject

func (project *Project) UploadObject(ctx context.Context, bucket, key string, options *UploadOptions) (upload *Upload, err error)

UploadObject starts an upload to the specific key.

type SharePrefix

type SharePrefix struct {
	Bucket string
	// Prefix is the prefix of the shared object keys.
	Prefix string
}

SharePrefix defines a prefix that will be shared.

type SystemMetadata

type SystemMetadata struct {
	Created       time.Time
	Expires       time.Time
	ContentLength int64
}

SystemMetadata contains information about the object that cannot be changed directly.

type Upload

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

Upload is an upload to Storj Network.

func (*Upload) Abort

func (upload *Upload) Abort() error

Abort aborts the upload.

Returns ErrUploadDone when either Abort or Commit has already been called.

func (*Upload) Commit

func (upload *Upload) Commit() error

Commit commits data to the store.

Returns ErrUploadDone when either Abort or Commit has already been called.

func (*Upload) Info

func (upload *Upload) Info() *Object

Info returns the last information about the uploaded object.

func (*Upload) SetCustomMetadata

func (upload *Upload) SetCustomMetadata(ctx context.Context, custom CustomMetadata) error

SetCustomMetadata updates custom metadata to be included with the object. If it is nil, it won't be modified.

func (*Upload) Write

func (upload *Upload) Write(p []byte) (n int, err error)

Write uploads len(p) bytes from p to the object's data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early.

type UploadOptions

type UploadOptions struct {
	// When Expires is zero, there is no expiration.
	Expires time.Time
}

UploadOptions contains additional options for uploading.

Directories

Path Synopsis
Package backcomp contains utilities for handling backwards incompatible changes.
Package backcomp contains utilities for handling backwards incompatible changes.
internal
private

Jump to

Keyboard shortcuts

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