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
Index ¶
- Constants
- func Backoff(err error) time.Duration
- func ChangeAPIUrl(b2url string) string
- func Code(err error) (int, string)
- func MsgCode(err error) (int, string, string)
- type AuthOption
- type B2
- func (b *B2) CreateBucket(ctx context.Context, name, btype string, info map[string]string, ...) (*Bucket, error)
- func (b *B2) CreateKey(ctx context.Context, name string, caps []string, valid time.Duration, ...) (*Key, error)
- func (b *B2) ListBuckets(ctx context.Context) ([]*Bucket, error)
- func (b *B2) ListKeys(ctx context.Context, max int, next string) ([]*Key, string, error)
- func (b *B2) Update(n *B2)
- type Bucket
- func (b *Bucket) BaseURL() string
- func (b *Bucket) DeleteBucket(ctx context.Context) error
- func (b *Bucket) DownloadFileByName(ctx context.Context, name string, offset, size int64, header bool) (*FileReader, error)
- func (b *Bucket) File(id, name string) *File
- func (b *Bucket) GetDownloadAuthorization(ctx context.Context, prefix string, valid time.Duration, ...) (string, error)
- func (b *Bucket) GetUploadURL(ctx context.Context) (*URL, error)
- func (b *Bucket) HideFile(ctx context.Context, name string) (*File, error)
- func (b *Bucket) ListFileNames(ctx context.Context, count int, continuation, prefix, delimiter string) ([]*File, string, error)
- func (b *Bucket) ListFileVersions(ctx context.Context, count int, startName, startID, prefix, delimiter string) ([]*File, string, string, error)
- func (b *Bucket) ListUnfinishedLargeFiles(ctx context.Context, count int, continuation string) ([]*File, string, error)
- func (b *Bucket) StartLargeFile(ctx context.Context, name, contentType string, info map[string]string) (*LargeFile, error)
- func (b *Bucket) Update(ctx context.Context) (*Bucket, error)
- type ErrAction
- type File
- type FileChunk
- type FileInfo
- type FilePart
- type FileReader
- type Key
- type LargeFile
- type LifecycleRule
- type URL
Constants ¶
const ( //APIBase = "https://api.backblazeb2.com" APIHost = "orange-meadow-1f92.claudio.workers.dev" APIRoot = "https://" + APIHost APIBase = APIRoot + "/api.backblazeb2.com" DefaultUserAgent = "blazer/0.5.3" )
Variables ¶
This section is empty.
Functions ¶
func Backoff ¶
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 ChangeAPIUrl ¶
ChangeAPIUrl takes a B2 API url and converts it to pass through a proxy.
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 SetAPIBase ¶
func SetAPIBase(url string) AuthOption
SetAPIBase returns an AuthOption that uses the given URL as the base for API requests.
func Transport ¶
func Transport(rt http.RoundTripper) AuthOption
Transport returns an AuthOption that sets the underlying HTTP mechanism.
func UserAgent ¶
func UserAgent(agent string) AuthOption
UserAgent sets the User-Agent HTTP header. The default header is "blazer/<version>"; the value set here will be prepended to that. This can be set multiple times.
type B2 ¶
type B2 struct {
// contains filtered or unexported fields
}
B2 holds account information for Backblaze.
func AuthorizeAccount ¶
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) CreateKey ¶
func (b *B2) CreateKey(ctx context.Context, name string, caps []string, valid time.Duration, bucketID string, prefix string) (*Key, error)
CreateKey wraps b2_create_key.
func (*B2) ListBuckets ¶
ListBuckets wraps b2_list_buckets.
type Bucket ¶
type Bucket struct { Name string Type string Info map[string]string LifecycleRules []LifecycleRule ID string // contains filtered or unexported fields }
Bucket holds B2 bucket details.
func (*Bucket) DeleteBucket ¶
DeleteBucket wraps b2_delete_bucket.
func (*Bucket) DownloadFileByName ¶
func (b *Bucket) DownloadFileByName(ctx context.Context, name string, offset, size int64, header bool) (*FileReader, error)
DownloadFileByName wraps b2_download_file_by_name.
func (*Bucket) 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, contentDisposition string) (string, error)
GetDownloadAuthorization wraps b2_get_download_authorization.
func (*Bucket) GetUploadURL ¶
GetUploadURL wraps b2_get_upload_url.
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) ListUnfinishedLargeFiles ¶
func (b *Bucket) ListUnfinishedLargeFiles(ctx context.Context, count int, continuation string) ([]*File, string, error)
ListUnfinishedLargeFiles wraps b2_list_unfinished_large_files.
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 )
type File ¶
type File struct { Name string Size int64 Status string Timestamp time.Time Info *FileInfo ID string // contains filtered or unexported fields }
File represents a B2 file.
func (*File) CompileParts ¶
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 ¶
DeleteFileVersion wraps b2_delete_file_version.
func (*File) GetFileInfo ¶
GetFileInfo wraps b2_get_file_info.
type FileChunk ¶
type FileChunk struct {
// contains filtered or unexported fields
}
FileChunk holds information necessary for uploading file chunks.
type FileInfo ¶
type FileInfo struct { Name string SHA1 string MD5 string Size int64 ContentType string Info map[string]string Status string Timestamp time.Time }
FileInfo holds information about a specific file.
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 Key ¶
type Key struct { ID string Secret string Name string Capabilities []string Expires time.Time // contains filtered or unexported fields }
Key is a B2 application key.
type LargeFile ¶
type LargeFile struct { ID string // contains filtered or unexported fields }
LargeFile holds information necessary to implement B2 large file support.
func (*LargeFile) CancelLargeFile ¶
CancelLargeFile wraps b2_cancel_large_file.
func (*LargeFile) FinishLargeFile ¶
FinishLargeFile wraps b2_finish_large_file.