Documentation
¶
Overview ¶
Package b2 is a go library for backblaze B2 Cloud Storage.
Index ¶
- Constants
- func GetKeyFromEnv() (string, string)
- type ApplicationKey
- type ApplicationKeys
- type AuthResponse
- type B2
- func (b *B2) Auth() error
- func (b *B2) CancelLargeFile(fileId string) error
- func (b *B2) CreateBucket(bucketName, bucketType string, bucketInfo map[string]string, ...) (*Bucket, error)
- func (b *B2) CreateKey(capabilities []string, keyName string, validDurationInSeconds int64, ...) (*ApplicationKey, error)
- func (b *B2) DeleteBucket(bucketId string) error
- func (b *B2) DeleteFileVersion(fileName, fileId string) error
- func (b *B2) DeleteKey(key *ApplicationKey) error
- func (b *B2) DownloadFileById(fileId, filePath string, needAuth bool, report func(int64, int64)) error
- func (b *B2) DownloadFileByName(bucketName, fileName, filePath string, needAuth bool, ...) error
- func (b *B2) FinishLargeFile(fileId string, partSha1Array []string) (*File, error)
- func (b *B2) GetAuth() AuthResponse
- func (b *B2) GetDownloadAuthorization(bucketId, fileNamePrefix string, validDurationInSeconds int64) (*DownloadUrlToken, error)
- func (b *B2) GetFileInfo(fileId string) (*File, error)
- func (b *B2) GetPublicFileDownloadURL(bucketName, fileName string) string
- func (b *B2) GetUploadPartUrl(fileId string) (*UploadUrlToken, error)
- func (b *B2) GetUploadUrl(bucketId string) (*UploadUrlToken, error)
- func (b *B2) HideFile(bucketId, fileName string) error
- func (b *B2) ListBuckets(bucketId, bucketName, bucketTypes string) ([]*Bucket, error)
- func (b *B2) ListFileNames(bucketId, startFileName, prefix, delimiter string, maxFileCount int64) ([]*File, error)
- func (b *B2) ListFileVersions(bucketId, startFileName, startFileId, prefix, delimiter string, ...) ([]*File, error)
- func (b *B2) ListKeys(maxKeyCount int64, startApplicationKeyId string) (*ApplicationKeys, error)
- func (b *B2) ListParts(fileId string, startPartNumber int64, maxPartNumber int64) ([]*Part, error)
- func (b *B2) ListUnfinishedLargeFiles(bucketId, namePrefix string, startFileId string, maxfileCount int64) ([]*File, error)
- func (b *B2) SetAuth(auth AuthResponse)
- func (b *B2) StartLargeFile(bucketId, fileName string, fileInfo map[string]string) (*File, error)
- func (b *B2) UpdateBucket(bucket *Bucket, ifRevisionIs bool) (*Bucket, error)
- func (b *B2) UploadFile(uploadUrlToken *UploadUrlToken, filePath string, progress func(int64, int64)) (*File, error)
- func (b *B2) UploadPart(uploadUrlToken *UploadUrlToken, filePath string, ...) (string, error)
- type Bucket
- type CorsRule
- type DownloadUrlToken
- type ErrorResponse
- type File
- type FileInfo
- type LifecycleRule
- type Part
- type ProgressReaderWriter
- type UploadUrlToken
Constants ¶
const AUTH_URL = "https://api.backblazeb2.com/b2api/v1/b2_authorize_account"
const DELETE_BUCKETS = "deleteBuckets"
const DELETE_FILES = "deleteFiles"
const DELETE_KEYS = "deleteKeys"
const LIST_BUCKETS = "listBuckets"
const LIST_FILES = "listFiles"
const LIST_KEYS = "listKeys"
Capability
const PRIVATE = "allPrivate"
const PUBLIC = "allPublic"
const READ_FILES = "readFiles"
const SHARE_FILES = "shareFiles"
const WRITE_BUCKETS = "writeBuckets"
const WRITE_FILES = "writeFiles"
const WRITE_KEYS = "writeKeys"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ApplicationKey ¶
type ApplicationKey struct {
ApplicationKeyId string `json:"applicationKeyId"`
ApplicationKey string `json:"applicationKey"`
KeyName string `json:"keyName"`
Capabilities []string `json:"capabilities"`
ExpirationTimestamp int64 `json:"expirationTimestamp,omitempty"`
BucketId string `json:"bucketId,omitempty"`
NamePrefix string `json:"namePrefix,omitempty"`
}
type ApplicationKeys ¶
type ApplicationKeys struct {
Keys []*ApplicationKey `json:"keys"`
NextApplicationKeyId string `json:"nextApplicationKeyId,omitempty"`
}
type AuthResponse ¶
type AuthResponse struct {
AccountId string `json:"accountId"`
AuthorizationToken string `json:"authorizationToken"`
ApiUrl string `json:"apiUrl"`
DownloadUrl string `json:"downloadUrl"`
RecommendedPartSize int64 `json:"recommendedPartSize"`
AbsoluteMinimumPartSize int64 `json:"absoluteMinimumPartSize"`
}
type B2 ¶
B2 is used to initialize your b2 account and applicationkey
func (*B2) CancelLargeFile ¶
CancelLargeFile cancel parted uploaded. See "b2_cancel_large_file" for an introduction: https://www.backblaze.com/b2/docs/b2_cancel_large_file.html
Parameter fileId is required. CancelLargeFile return an error.
func (*B2) CreateBucket ¶
func (b *B2) CreateBucket(bucketName, bucketType string, bucketInfo map[string]string, corsRules []CorsRule, lifecycleRules []LifecycleRule) (*Bucket, error)
CreateBucket create a bucket. See "b2_create_bucket" for an introduction: https://www.backblaze.com/b2/docs/b2_create_bucket.html
Parameter bucketName and bucketType are required. You can pass empty map or slice for simplicity. CreateBucket returned a Bucket pointer and an error.
func (*B2) CreateKey ¶
func (b *B2) CreateKey(capabilities []string, keyName string, validDurationInSeconds int64, bucketId string, namePrefix string) (*ApplicationKey, error)
CreateKey creates a new application key. See "b2_create_key" for an introduction: https://www.backblaze.com/b2/docs/b2_create_key.html
Parameter capabilities, keyName are required. CreateKey return an ApplicationKey pointer and an error.
func (*B2) DeleteBucket ¶
DeleteBucket delete a bucket. See "b2_delete_bucket" for an introduction: https://www.backblaze.com/b2/docs/b2_delete_bucket.html
Parameter bucketId is required, you can get bucketId from an Bucket struct. DeleteBucket returned nil if success, return error if failed.
func (*B2) DeleteFileVersion ¶
DeleteFileVersion delete a file version from b2 Cloud Storage. If the version you delete is the lastest version, and there are older versions, then the most recent older version will become the current version. See "b2_delete_file_version" for an introduction: https://www.backblaze.com/b2/docs/b2_delete_file_version.html
Parameter fileName and fileId are required, you can get these from any File struct. DeleteFileVersion return nil if successed, return error if failed.
func (*B2) DeleteKey ¶
func (b *B2) DeleteKey(key *ApplicationKey) error
DeleteKey deletes the application key specified. See "b2_delete_key" for an introduction: https://www.backblaze.com/b2/docs/b2_delete_key.html
Parameter key is required. DeleteKey return nil if delete successd or error if something error happened.
func (*B2) DownloadFileById ¶
func (b *B2) DownloadFileById(fileId, filePath string, needAuth bool, report func(int64, int64)) error
DownloadFileById downlaod file from b2 Cloud Storage using fileId. See "b2_download_file_by_id" for an introduction: https://www.backblaze.com/b2/docs/b2_download_file_by_id.html
Parameter fileId and filePath are required, if the bucket is private, you should pass needAuth as true. Parameter filePath is the local file path you want to save. DownloadFileById return nil if successed, return error if failed.
func (*B2) DownloadFileByName ¶
func (b *B2) DownloadFileByName(bucketName, fileName, filePath string, needAuth bool, report func(int64, int64)) error
DownloadFileByName downlaod file from b2 Cloud Storage using bucketName and fileName. See "b2_download_file_by_name" for an introduction: https://www.backblaze.com/b2/docs/b2_download_file_by_name.html
Parameter bucketName, fileName and filePath are required, if the bucket is private, you should pass needAuth as true. Parameter filePath is the local file path you want to save. DownloadFileByName return nil if successed, return error if failed.
func (*B2) FinishLargeFile ¶
FinishLargeFile merge all parts uploaded. See "b2_finish_large_file" for an introduction: https://www.backblaze.com/b2/docs/b2_finish_large_file.html
Parameter fileId and partSha1Array are required. FinishLargeFile return a file pointer and an error.
func (*B2) GetAuth ¶
func (b *B2) GetAuth() AuthResponse
func (*B2) GetDownloadAuthorization ¶
func (b *B2) GetDownloadAuthorization(bucketId, fileNamePrefix string, validDurationInSeconds int64) (*DownloadUrlToken, error)
GetDownloadAuthorization create a download url and a token. See "b2_get_download_authorization" for an introduction: https://www.backblaze.com/b2/docs/b2_get_download_authorization.html
Parameter bucketId, fileNamePrefix and validDurationInSeconds are required. GetDownloadAuthorization return a DownloadUrlToken pointer and an error.
func (*B2) GetFileInfo ¶
GetFileInfo get the file info. See "b2_get_file_info" for an introduction: https://www.backblaze.com/b2/docs/b2_get_file_info.html
Parameter fileId is required, you can get fileId from any File struct. GetFileInfo return a File pointer and an error.
func (*B2) GetPublicFileDownloadURL ¶
func (*B2) GetUploadPartUrl ¶
func (b *B2) GetUploadPartUrl(fileId string) (*UploadUrlToken, error)
GetUploadPartUrl return uploadUrlToken for a registered large file. See "b2_get_upload_part_url" for an introduction: https://www.backblaze.com/b2/docs/b2_get_upload_part_url.html
Parameter fileId is required. GetUploadPartUrl return a File pointer and an error.
func (*B2) GetUploadUrl ¶
func (b *B2) GetUploadUrl(bucketId string) (*UploadUrlToken, error)
GetUploadUrl hide the file. See "b2_get_upload_url" for an introduction: https://www.backblaze.com/b2/docs/b2_get_upload_url.html
Parameter bucketId is required, you can get bucketId from any Bucket struct. GetUploadUrl return a UploadUrlToken pointer and an error.
func (*B2) HideFile ¶
HideFile hide the file. See "b2_hide_file" for an introduction: https://www.backblaze.com/b2/docs/b2_hide_file.html
Parameter bucketId and fileName is required. HideFile return nil if successed, return error if failed.
func (*B2) ListBuckets ¶
ListBuckets update a bucket. See "b2_list_buckets" for introduction: https://www.backblaze.com/b2/docs/b2_list_buckets.html
All parameter are optional, you can pass empty value for simplicity. List returned a bucket array and an error.
func (*B2) ListFileNames ¶
func (b *B2) ListFileNames(bucketId, startFileName, prefix, delimiter string, maxFileCount int64) ([]*File, error)
ListFileNames list files names. See "b2_list_file_names" for an introduction: https://www.backblaze.com/b2/docs/b2_list_file_names.html
Parameter bucketId is required. You can pass other empty value for other parameter for simplicity. ListFileNames return a File array and an error.
func (*B2) ListFileVersions ¶
func (b *B2) ListFileVersions(bucketId, startFileName, startFileId, prefix, delimiter string, maxFileCount int64) ([]*File, error)
ListFileVersions list files versions. See "b2_list_file_versions" for an introduction: https://www.backblaze.com/b2/docs/b2_list_file_versions.html
Parameter bucketId is required. You can pass other empty value for other parameter for simplicity. ListFileVersions return a File array and an error.
func (*B2) ListKeys ¶
func (b *B2) ListKeys(maxKeyCount int64, startApplicationKeyId string) (*ApplicationKeys, error)
ListKeys list application keys associated with an account. See "b2_list_keys" for an introduction: https://www.backblaze.com/b2/docs/b2_list_keys.html All parameters are optional. ListKeys return an list of application pointer and an error.
func (*B2) ListParts ¶
ListParts return parts of a large file. See "b2_list_parts" for an introduction: https://www.backblaze.com/b2/docs/b2_list_parts.html
All parameters are required. ListParts return uploaded parts of a large file.
func (*B2) ListUnfinishedLargeFiles ¶
func (b *B2) ListUnfinishedLargeFiles(bucketId, namePrefix string, startFileId string, maxfileCount int64) ([]*File, error)
ListUnfinishedLargeFiles lists unfinished large files. See "b2_list_unfinished_large_files" for an introduction: https://www.backblaze.com/b2/docs/b2_list_unfinished_large_files.html
All parameters are required. ListUnfinishedLargeFiles return an array of file and an error.
func (*B2) SetAuth ¶
func (b *B2) SetAuth(auth AuthResponse)
func (*B2) StartLargeFile ¶
StartLargeFile register a file to upload See "b2_start_large_file" for an introduction: https://www.backblaze.com/b2/docs/b2_start_large_file.html
Parameter bucketId and fileName are required. You can pass other empty value for other parameter for simplicity. StartLargeFile return a File array and an error.
func (*B2) UpdateBucket ¶
UpdateBucket update a bucket. See "b2_update_bucket" for an introduction: https://www.backblaze.com/b2/docs/b2_update_bucket.html
Parameter bucket is required, you can pass ifRevisionIs as false for simplicity. UpdateBucket returned a bucket pointer and an error.
func (*B2) UploadFile ¶
func (b *B2) UploadFile(uploadUrlToken *UploadUrlToken, filePath string, progress func(int64, int64)) (*File, error)
UploadFile upload file to b2 Close Storage. See "b2_upload_file" for an introduction: https://www.backblaze.com/b2/docs/b2_upload_file.html
Parameter uploadUrlToken and filePath are required. UploadFile return a File pointer and an error.
func (*B2) UploadPart ¶
func (b *B2) UploadPart(uploadUrlToken *UploadUrlToken, filePath string, offset, size, partNumber int64, progress func(int64, int64)) (string, error)
UploadPart upload file part to b2 Close Storage. See "b2_upload_part" for an introduction: https://www.backblaze.com/b2/docs/b2_upload_part.html
All parameters are required. UploadPart return a content sha1 and an error.
type Bucket ¶
type Bucket struct {
BucketId string `json:"bucketId"`
BucketName string `json:"bucketName"`
BucketType string `json:"bucketType"`
BucketInfo map[string]string `json:"bucketInfo,omitempty"`
CorsRules []CorsRule `json:"corsRules,omitempty"`
LifecycleRules []LifecycleRule `json:"lifecycleRules,omitempty"`
Revision int64 `json:"revision,omitempty"`
}
type CorsRule ¶
type CorsRule struct {
CorsRuleName string `json:"corsRuleName"`
AllowedOrigins []string `json:"allowedOrigins"`
AllowedHeaders []string `json:"allowedHeaders"`
AllowedOperations []string `json:"allowedOperations"`
ExposeHeaders []string `json:"exposeHeaders"`
MaxAgeSeconds int64 `json:"maxAgeSeconds"`
}
type DownloadUrlToken ¶
type ErrorResponse ¶
type File ¶
type File struct {
FileId string `json:"fileId"`
FileName string `json:"fileName"`
ContentLength int64 `json:"contentLength"`
ContentType string `json:"contentType"`
ContentSha1 string `json:"contentSha1"`
FileInfo FileInfo `json:"fileInfo"`
Action string `json:"action"`
UploadTimestamp int64 `json:"uploadTimestamp"`
}
type LifecycleRule ¶
type Part ¶
type ProgressReaderWriter ¶
type ProgressReaderWriter struct {
Reader io.Reader
Writer io.Writer
Total int64
Done int64
Report func(int64, int64)
}
func (*ProgressReaderWriter) Read ¶
func (prw *ProgressReaderWriter) Read(p []byte) (int, error)
func (*ProgressReaderWriter) Write ¶
func (prw *ProgressReaderWriter) Write(p []byte) (int, error)
Source Files
¶
- auth.go
- b2.go
- big.go
- bucket.go
- download.go
- error.go
- file.go
- key.go
- models.go
- small.go
- test_utils.go
- utils.go