base

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2017 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Overview

Package base provides a very low-level interface on top of the B2 v1 API. It is not intended to be used directly.

It currently lacks support for the following APIs:

b2_download_file_by_id b2_list_unfinished_large_files

Index

Constants

This section is empty.

Variables

View Source
var (
	APIBase = "https://api.backblazeb2.com"
)

Functions

func Backoff

func Backoff(err error) time.Duration

Backoff returns an appropriate amount of time to wait, given an error, if any was returned by the server. If the return value is 0, but Action indicates Retry, the user should implement their own exponential backoff, beginning with one second.

func Code

func Code(err error) (int, string)

Code returns the error code and message.

Types

type AuthOption

type AuthOption func(*b2Options)

An AuthOption allows callers to choose per-session settings.

func ExpireSomeAuthTokens

func ExpireSomeAuthTokens() AuthOption

ExpireSomeAuthTokens requests intermittent authentication failures from the B2 service.

func FailSomeUploads

func FailSomeUploads() AuthOption

FailSomeUploads requests intermittent upload failures from the B2 service. This is mostly useful for testing.

func ForceCapExceeded

func ForceCapExceeded() AuthOption

ForceCapExceeded requests a cap limit from the B2 service. This causes all uploads to be treated as if they would exceed the configure B2 capacity.

func Transport

func Transport(rt http.RoundTripper) AuthOption

Transport returns an AuthOption that sets the underlying HTTP mechanism.

type B2

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

B2 holds account information for Backblaze.

func AuthorizeAccount

func AuthorizeAccount(ctx context.Context, account, key string, opts ...AuthOption) (*B2, error)

AuthorizeAccount wraps b2_authorize_account.

func (*B2) CreateBucket

func (b *B2) CreateBucket(ctx context.Context, name, btype string, info map[string]string, rules []LifecycleRule) (*Bucket, error)

CreateBucket wraps b2_create_bucket.

func (*B2) ListBuckets

func (b *B2) ListBuckets(ctx context.Context) ([]*Bucket, error)

ListBuckets wraps b2_list_buckets.

func (*B2) Update

func (b *B2) Update(n *B2)

Update replaces the B2 object with a new one, in-place.

type Bucket

type Bucket struct {
	Name           string
	Type           string
	Info           map[string]string
	LifecycleRules []LifecycleRule
	// contains filtered or unexported fields
}

Bucket holds B2 bucket details.

func (*Bucket) BaseURL

func (b *Bucket) BaseURL() string

BaseURL returns the base part of the download URLs.

func (*Bucket) DeleteBucket

func (b *Bucket) DeleteBucket(ctx context.Context) error

DeleteBucket wraps b2_delete_bucket.

func (*Bucket) DownloadFileByName

func (b *Bucket) DownloadFileByName(ctx context.Context, name string, offset, size int64) (*FileReader, error)

DownloadFileByName wraps b2_download_file_by_name.

func (*Bucket) File

func (b *Bucket) File(id, name string) *File

File returns a bare File struct, but with the appropriate id and b2 interfaces.

func (*Bucket) GetDownloadAuthorization

func (b *Bucket) GetDownloadAuthorization(ctx context.Context, prefix string, valid time.Duration) (string, error)

GetDownloadAuthorization wraps b2_get_download_authorization.

func (*Bucket) GetUploadURL

func (b *Bucket) GetUploadURL(ctx context.Context) (*URL, error)

GetUploadURL wraps b2_get_upload_url.

func (*Bucket) HideFile

func (b *Bucket) HideFile(ctx context.Context, name string) (*File, error)

HideFile wraps b2_hide_file.

func (*Bucket) ListFileNames

func (b *Bucket) ListFileNames(ctx context.Context, count int, continuation, prefix, delimiter string) ([]*File, string, error)

ListFileNames wraps b2_list_file_names.

func (*Bucket) ListFileVersions

func (b *Bucket) ListFileVersions(ctx context.Context, count int, startName, startID, prefix, delimiter string) ([]*File, string, string, error)

ListFileVersions wraps b2_list_file_versions.

func (*Bucket) StartLargeFile

func (b *Bucket) StartLargeFile(ctx context.Context, name, contentType string, info map[string]string) (*LargeFile, error)

StartLargeFile wraps b2_start_large_file.

func (*Bucket) Update

func (b *Bucket) Update(ctx context.Context) (*Bucket, error)

Update wraps b2_update_bucket.

type ErrAction

type ErrAction int

ErrAction is an action that a caller can take when any function returns an error.

const (
	// ReAuthenticate indicates that the B2 account authentication tokens have
	// expired, and should be refreshed with a new call to AuthorizeAccount.
	ReAuthenticate ErrAction = iota

	// AttemptNewUpload indicates that an upload's authentication token (or URL
	// endpoint) has expired, and that users should request new ones with a call
	// to GetUploadURL or GetUploadPartURL.
	AttemptNewUpload

	// Retry indicates that the caller should wait an appropriate amount of time,
	// and then reattempt the RPC.
	Retry

	// Punt means that there is no useful action to be taken on this error, and
	// that it should be displayed to the user.
	Punt
)

func Action

func Action(err error) ErrAction

Action checks an error and returns a recommended course of action.

type File

type File struct {
	Name      string
	Size      int64
	Status    string
	Timestamp time.Time
	Info      *FileInfo
	// contains filtered or unexported fields
}

File represents a B2 file.

func (*File) CompileParts

func (f *File) CompileParts(size int64, seen map[int]string) *LargeFile

CompileParts returns a LargeFile that can accept new data. Seen is a mapping of completed part numbers to SHA1 strings; size is the total size of all the completed parts to this point.

func (*File) DeleteFileVersion

func (f *File) DeleteFileVersion(ctx context.Context) error

DeleteFileVersion wraps b2_delete_file_version.

func (*File) GetFileInfo

func (f *File) GetFileInfo(ctx context.Context) (*FileInfo, error)

GetFileInfo wraps b2_get_file_info.

func (*File) ListParts

func (f *File) ListParts(ctx context.Context, next, count int) ([]*FilePart, int, error)

ListParts wraps b2_list_parts.

type FileChunk

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

FileChunk holds information necessary for uploading file chunks.

func (*FileChunk) Reload

func (fc *FileChunk) Reload(ctx context.Context) error

Reload reloads FileChunk in-place.

func (*FileChunk) UploadPart

func (fc *FileChunk) UploadPart(ctx context.Context, r io.Reader, sha1 string, size, index int) (int, error)

UploadPart wraps b2_upload_part.

type FileInfo

type FileInfo struct {
	Name        string
	SHA1        string
	Size        int64
	ContentType string
	Info        map[string]string
	Status      string
	Timestamp   time.Time
}

FileInfo holds information about a specific file.

type FilePart

type FilePart struct {
	Number int
	SHA1   string
	Size   int64
}

FilePart is a piece of a started, but not finished, large file upload.

type FileReader

type FileReader struct {
	io.ReadCloser
	ContentLength int
	ContentType   string
	SHA1          string
	ID            string
	Info          map[string]string
}

FileReader is an io.ReadCloser that downloads a file from B2.

type LargeFile

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

LargeFile holds information necessary to implement B2 large file support.

func (*LargeFile) CancelLargeFile

func (l *LargeFile) CancelLargeFile(ctx context.Context) error

CancelLargeFile wraps b2_cancel_large_file.

func (*LargeFile) FinishLargeFile

func (l *LargeFile) FinishLargeFile(ctx context.Context) (*File, error)

FinishLargeFile wraps b2_finish_large_file.

func (*LargeFile) GetUploadPartURL

func (l *LargeFile) GetUploadPartURL(ctx context.Context) (*FileChunk, error)

GetUploadPartURL wraps b2_get_upload_part_url.

type LifecycleRule

type LifecycleRule struct {
	Prefix                 string
	DaysNewUntilHidden     int
	DaysHiddenUntilDeleted int
}

type URL

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

URL holds information from the b2_get_upload_url API.

func (*URL) Reload

func (url *URL) Reload(ctx context.Context) error

Reload reloads URL in-place, by reissuing a b2_get_upload_url and overwriting the previous values.

func (*URL) UploadFile

func (u *URL) UploadFile(ctx context.Context, r io.Reader, size int, name, contentType, sha1 string, info map[string]string) (*File, error)

UploadFile wraps b2_upload_file.

Jump to

Keyboard shortcuts

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