backblaze2

package module
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 38 Imported by: 0

README

backblaze2

map to api provided by back blaze b2 cloud

Testing failures on upload

X-Bz-Test-Mode: fail_some_uploads Add this to b2_upload_file API call, cause intermittent artificial failures, allowing you to test the resiliency of your code.

Testing authorization failures

Add this to authorization header X-Bz-Test-Mode: expire_some_account_authorization_tokens

Testing Upload 403 Forbidden error

X-Bz-Test-Mode: force_cap_exceeded header before making upload-related API calls. This will cause a cap limit failure, allowing you to verify correct behavior of your code.

Retry Header

429 Too Many Requests. B2 may limit API requests on a per-account basis. When the 429 status code is returned from an API, the response will also include a "Retry-After" header where the value is the number of seconds a developer should wait before re-issuing the command. This status code may be returned on any B2 API.

Documentation

Index

Constants

View Source
const (
	AppFolderName = ".cloudstore"
	// UploadFolder exported folder name
	UploadFolder = "upload"
	MaxAuthTry   = 1000
)
View Source
const (
	// MinPartSize in MB
	MinPartSize = 6
	// MinParts count size
	MinParts = 2
	// MaxUploadTB size in TB
	MaxUploadTB = 10

	DownSplitThresh = 200000000
)
View Source
const DownloadFileChunk = 10 * (1 << 20)

Variables

View Source
var AuthCounter = 0
View Source
var (
	//MaxPerSessionUploadPerPart sessions
	MaxPerSessionUploadPerPart = 3
)

Functions

func UploaderDir

func UploaderDir(bucketName string) string

UploaderDir build uploader directory

Types

type Cloud

type Cloud struct {
	AuthConfig   b2api.AuthConfig
	AuthResponse *b2api.AuthorizationResp
}

func CloudStore

func CloudStore(accountId, appId, appName string) *Cloud

func (*Cloud) AuthAccount

func (c *Cloud) AuthAccount()

func (*Cloud) CancelLargeFile

func (c *Cloud) CancelLargeFile(fileId string) (*b2api.CanxUpLgFileResp, errs.Error)

CancelLargeFile cancel large file upload process

func (*Cloud) CreateBucket

func (c *Cloud) CreateBucket(bucketName string, bucketType b2api.BucketType,
	bucketInfo map[string]interface{}, corsRules []b2api.CorsRules, lifeCycleRules []b2api.LifecycleRules) (*b2api.CreateBucketResp, errs.Error)

CreateBucket create a bucket on account

func (*Cloud) CreateKey

func (c *Cloud) CreateKey(keyName, keyBucket string, capabilities []string) (*b2api.CreateKeyResp, errs.Error)

CreateKey create account key

func (*Cloud) DeleteBucket

func (c *Cloud) DeleteBucket(bucketId string) (*b2api.DeleteBucketResp, errs.Error)

DeleteBucket remove from account

func (*Cloud) DeleteFile

func (c *Cloud) DeleteFile(fileName, fileID string) (*b2api.DeleteFileVersionResponse, errs.Error)

DeleteFile deletes file version by file id

func (*Cloud) DeleteKey

func (c *Cloud) DeleteKey(keyId string) (*b2api.DeleteKeyResp, errs.Error)

DeleteKey delete account key

func (*Cloud) DownloadByID

func (c *Cloud) DownloadByID(fileID, byteRange string) (map[string]interface{}, errs.Error)
DownloadByID downloads file by id

In map:

body			- content of file
Content-Length
Content-Type
X-Bz-File-Id
X-Bz-File-Name
X-Bz-Content-Sha1
X-Bz-Info-author
X-Bz-Upload-Timestamp
Cache-Control : max-age (only); inherited from Bucket Info

PLUS:

X-Bz-Info-* headers for any custom file info during upload

func (*Cloud) DownloadByName

func (c *Cloud) DownloadByName(bucketName, fileName string) (map[string]interface{}, errs.Error)
GetDownloadAuth required prior to download

In map:

body			- content of file
Content-Length
Content-Type
X-Bz-File-Id
X-Bz-File-Name
X-Bz-Content-Sha1
X-Bz-Info-author
X-Bz-Upload-Timestamp
Cache-Control : max-age (only); inherited from Bucket Info

PLUS:

X-Bz-Info-* headers for any custom file info during upload

func (*Cloud) FinishLargeFileUpload

func (c *Cloud) FinishLargeFileUpload(fileId string, sha1Array []string) (*b2api.FinishUpLgFileResp, errs.Error)

FinishLargeFileUpload call complete on large upload

func (*Cloud) GetDownloadAuth

func (c *Cloud) GetDownloadAuth(bucketID, filenamePrefix string, validDurationInSeconds int64) (*b2api.DownloadAuthResponse, errs.Error)

GetDownloadAuth required prior to download

func (*Cloud) GetFileInfo

func (c *Cloud) GetFileInfo(fileID string) (*b2api.GetFileInfoResponse, errs.Error)

GetFileInfo provides file information

func (*Cloud) GetUploadPartURL

func (c *Cloud) GetUploadPartURL(fileID string) (*b2api.GetFileUploadPartResponse, errs.Error)

func (*Cloud) HideFile

func (c *Cloud) HideFile(bucketId, fileName string) (*b2api.HideFileResponse, errs.Error)

HideFile hides file by putting 0 content length in history

func (*Cloud) ListBuckets

func (c *Cloud) ListBuckets(bucketId, bucketName string, bucketType []b2api.BucketType) (*b2api.ListBucketsResp, errs.Error)

ListBuckets list out buckets for account

func (*Cloud) ListFileVersions

func (c *Cloud) ListFileVersions(bucketId, fileName, startFileName, startFileID string, qty int) (*b2api.ListFileVersionsResponse, errs.Error)

ListFileVersions lists out all versions of file

func (*Cloud) ListFiles

func (c *Cloud) ListFiles(bucketId, filename, startFileName string, qty int) (*b2api.ListFilesResponse, errs.Error)

ListFiles list files by name or all in bucket

func (*Cloud) ListKeys

func (c *Cloud) ListKeys() (*b2api.KeysResp, errs.Error)

ListKeys list account keys

func (*Cloud) ListPartsURL

func (c *Cloud) ListPartsURL(fileID string, startPartNo, maxPartCount int64) (*b2api.ListPartsResponse, errs.Error)

func (*Cloud) ListUnfinishedLargeFiles

func (c *Cloud) ListUnfinishedLargeFiles(bucketID string) (*b2api.ListUnfinishedLargeFilesResponse, errs.Error)

ListUnfinishLargeFiles show unfinished large file uploads

func (*Cloud) MultipartDownloadById

func (c *Cloud) MultipartDownloadById(fileID, localFilePath, fileNameOverride string) (string, error)

func (*Cloud) SendParts

func (c *Cloud) SendParts(up *Upload) (bool, error)

SendParts send parts to target

func (*Cloud) StartLargeFile

func (c *Cloud) StartLargeFile(bucketID, fileInfo string, up *Upload) (*b2api.StartLargeFileResponse, errs.Error)

StartLargeFile create initial start call

func (*Cloud) UpdateBucket

func (c *Cloud) UpdateBucket(bucketId string, bucketType b2api.BucketType,
	bucketInfo map[string]interface{}, corsRules []b2api.CorsRules, lifeCycleRules []b2api.LifecycleRules) (*b2api.CreateBucketResp, errs.Error)

UpdateBucket update bucket properties

func (*Cloud) UploadFile

func (c *Cloud) UploadFile(bucketId string, up *Upload) (*b2api.UploadResp, errs.Error)

UploadFile file name and info must fit in 7k byte limit,

the file to be uploaded is the message body and is not encoded in any way.
	it's not URL encoded, it's not MIME encoded

func (*Cloud) UploadURL

func (c *Cloud) UploadURL(bucketId string) (*b2api.UploadURLResp, errs.Error)

UploadURL retrieve upload url

func (*Cloud) UploadVirtualFile

func (c *Cloud) UploadVirtualFile(bucketId, fname string, data []byte, lastMod int64) (*b2api.UploadResp, errs.Error)

type Rtnd

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

Rtnd returned struct

func NewRtnd

func NewRtnd(up *Upload) *Rtnd

NewRtnd create new Rtnd struct

func (*Rtnd) Response

func (r *Rtnd) Response(b []byte)

Response set response

type Upload

type Upload struct {
	AppName         string          `json:"-"`
	Bucket          string          `json:"bucket"`
	Filepath        string          `json:"filepath"`
	OverridePath    string          `json:"override_path"`
	UploadID        string          `json:"uploadid"`
	File            file.File       `json:"-"`
	FileID          string          `json:"fileId"`
	Parts           []*UploaderPart `json:"parts"`
	TotalPartsCount uint64          `json:"total_parts_count"`
	// contains filtered or unexported fields
}

Upload struct

func Load added in v0.0.25

func Load(filepath string) *Upload

func NewUploader

func NewUploader(bucketName, filepath, overridepath string) *Upload

New create upload object

func (*Upload) Available

func (u *Upload) Available() bool

Available file exists

func (*Upload) Completed

func (u *Upload) Completed() bool

Completed has this finished

func (*Upload) ComputePartTotal

func (u *Upload) ComputePartTotal() error

ComputePartTotal compute total parts

func (*Upload) Process

func (u *Upload) Process(c *Cloud) (string, error)

func (*Upload) SetupPartSizes

func (u *Upload) SetupPartSizes(fileID string)

SetupPartSizes determine part sizes Pass in part count Pass in data on each part size and status i.e. completed or not

func (*Upload) UpdateEtag

func (u *Upload) UpdateEtag(partID int, appName, tag string)

UpdateEtag update each etag

func (*Upload) ValidateOverMinPartSize

func (u *Upload) ValidateOverMinPartSize() bool

ValidateOverMinPartSize check size

func (*Upload) ValidateSize

func (u *Upload) ValidateSize() bool

ValidateSize check size

func (*Upload) WriteOutFileData2Upload

func (u *Upload) WriteOutFileData2Upload(app string)

WriteOut write out upload info

type UploaderPart

type UploaderPart struct {
	Size   int64  `json:"size"`
	PartID uint64 `json:"part"`
	Start  int64  `json:"start"`
	End    int64  `json:"end"`
	Etag   string `json:"etag"`
}

******************************************************* UploaderPart struct

func NewUploaderPart

func NewUploaderPart(part uint64, start, end, size int64) *UploaderPart

NewUploaderPart create uploader part

Directories

Path Synopsis
internal
env
uri

Jump to

Keyboard shortcuts

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