Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 1.12 KB

README.md

File metadata and controls

62 lines (47 loc) · 1.12 KB

b2

b2 is a [Backblaze B2 Cloud Storage] (https://www.backblaze.com/b2/cloud-storage.html) API client written in Go.

Usage

To use b2, import it and create an API client using your account ID and application key.

import (
	"github.com/ifo/b2"
)

b2api, err := b2.CreateB2(accountID, appKey)

Here are some examples:

Create a bucket:

bucket, err := b2api.CreateBucket("kitten-pictures", AllPublic)

Upload a file:

fileReader, err := os.Open("./path/to/kitten.jpg")
// handle err

fileMeta, err := bucket.UploadFile("kitten.jpg", fileReader, nil)

Download a file:

kittenFile, err := bucket.DownloadFileByName("kitten.jpg")
// handle err

err = ioutil.WriteFile(kittenFile.Meta.Name, kittenFile.Data, 0644)

Check for an API error:

kittenFile, err := bucket.DownloadFileByName("cat.jpg")
if err != nil {
	if err, ok := err.(APIError); ok {
		// this is an APIError
		fmt.Println(err.Message)
	}
}

TODO

  • Implement large file API
  • Integration tests
  • Example program

License

b2 is ISC licensed. Check out the LICENSE file.