npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

b2cloud

v0.5.3

Published

Module for interacting with back blaze b2cloud api

Downloads

12

Readme

B2Cloud

Circle CI

A module for interacting with Back Blaze B2Cloud

Configuration

In ~/.b2cloud.json place your credentials

i.e. { "accountId": "", "applicationKey": "" }

Helpers

  • function getBucketByName(bucketName, callback)
    • Retreives a bucket object by its name, rather than by bucketId
  • function uploadFile(filePath, bucketName, callback)
    • Uploads a file
  • function downloadFile(name, bucketName, savePath, range, callback)
    • Downloads a file
    • Range is an optional object with properties start and end i.e. { start: 0, end: 1000 }
    • Range is number of bytes (inclusive) that will be downloaded
    • See b2 documentation https://www.backblaze.com/b2/docs/b2_download_file_by_name.html

Please note this is being actively worked on and will soon support all API operations as listed here:

https://www.backblaze.com/b2/docs/

I also will be adding helpers methods such as uploadFile, getBucketByName to make it easier to use

Documentation

All methods can use promises or callbacks

Installation

npm install b2cloud

Setup a file .b2cloud in your home folder. Setup like this:,

{
        "accountId": "",
        "applicationKey": ""
}

Usage Example:

    var b2cloud = require('b2cloud');

    return b2cloud.authorize.getBasicAuth().then(function(auth) {
        console.log('authenticated', auth);

    });

Classes

Authorize

Kind: global class

new Authorize(cache)

| Param | Type | | --- | --- | | cache | object |

authorize.getBasicAuth([callback]) ⇒ object

Fetches an authenticated session for interacting with b2cloud.

Kind: instance method of Authorize Returns: object - auth Returns an authenticated session

| Param | Type | | --- | --- | | [callback] | function |

Bucket

Kind: global class

new Bucket(cache)

| Param | Type | Description | | --- | --- | --- | | cache | object | Object used for caching requests. |

bucket.createBucket(name, type, [callback]) ⇒ object

Creates a bucket in the b2cloud

Kind: instance method of Bucket Returns: object - The response from b2_create_bucket

| Param | Type | Description | | --- | --- | --- | | name | string | Name of the bucket | | type | string | Either allPublic or allPrivate, sets the bucket to public or private access. | | [callback] | function | The optional callback |

bucket.deleteBucket(bucketId, [callback]) ⇒ object

Deletes a bucket from the b2cloud

Kind: instance method of Bucket Returns: object - The response from b2_create_bucket

| Param | Type | Description | | --- | --- | --- | | bucketId | string | BucketId as recieved from listBuckets or getBucketByName | | [callback] | function | The optional callback |

bucket.listBuckets([callback]) ⇒ object

Lists all buckets you have created.

Kind: instance method of Bucket Returns: object - The response from b2_list_buckets

| Param | Type | Description | | --- | --- | --- | | [callback] | function | The optional callback. |

bucket.getBucketByName(name, [callback]) ⇒ object

Helper function that returns a bucket object by its name.

Kind: instance method of Bucket Returns: object - The response from b2_list_buckets

| Param | Type | Description | | --- | --- | --- | | name | string | The name of the bucket. | | [callback] | function | An optional callback |

bucket.listBucketFiles(name, [startFileName], [maxFileCount], [callback]) ⇒ object

Lists all files inside of a bucket.

Kind: instance method of Bucket Returns: object - The response from b2_list_file_names See: https://www.backblaze.com/b2/docs/b2_list_file_names.html

| Param | Type | Description | | --- | --- | --- | | name | string | The name of the bucket | | [startFileName] | string | If the number of files exceeds the response limit, this will set which file to start listing from | | [maxFileCount] | number | Max number of files to return, cannot be greater than 1000 | | [callback] | function | The optional callback |

File

Kind: global class

new File(cache)

Class constructor, instantiates auth and bucket classes

| Param | Type | Description | | --- | --- | --- | | cache | object | Cache object shared amongst classes. |

file.getUploadUrl(bucketName, [callback]) ⇒ object

Gets the uploadUrl for uploadinga file to b2cloud

Kind: instance method of File Returns: object - - The response from b2_get_upload_url

| Param | Type | Description | | --- | --- | --- | | bucketName | string | Name of the bucket to get a uploadUrl for | | [callback] | function | Optional callback |

file.uploadFile(filePath, bucketName, [callback]) ⇒ object

Helper function that automatically generates the uploadUrl, hashes the file and uploads it to b2cloud.

Kind: instance method of File Returns: object - - The newly created b2cloud object.

| Param | Type | Description | | --- | --- | --- | | filePath | string | The file path to the file you want to upload | | bucketName | string | The bucke to upload the file to. | | [callback] | function | The optional callback |

file.downloadFile(name, bucketName, savePath, range, [callback]) ⇒ Promsise

Downloads a file from b2cloud

Kind: instance method of File Returns: Promsise - That resolves if the file is downloaded succesfully, otherwise rejects. See: https://www.backblaze.com/b2/docs/b2_download_file_by_name.html

| Param | Type | Description | | --- | --- | --- | | name | string | Name of the file to download | | bucketName | string | Bucket the file resides in | | savePath | string | Path to save the file to | | range | object | The range object used to fetch only a byte range, byte range is inclusive | | range.start | number | The start byte to download | | range.end | number | The end byte to download | | [callback] | function | The optional callback |

file.deleteFileVersion(fileName, fileId, [callback]) ⇒ *

Deletes a specific version of a file from b2cloud.

Kind: instance method of File

| Param | Type | Description | | --- | --- | --- | | fileName | string | Name of the file to delete. | | fileId | string | The unique fileid to delete | | [callback] | function | Optional callback |