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

blazer-b2

v0.0.5

Published

Node API for BackBlaze B2

Downloads

13

Readme

blazer

blazer is a node js library for BackBlaze B2. Note that this is currently a work in progress and not all api is implemented yet.

Status:

0.0.3

  • implemented list_file_names, list_file_versions, get_file_info, hide_file, delete_file_version, 0.0.2
  • added b2session - helper to do automatic retries
  • added store management to help in persisting/reusing tokens 0.0.1
  • upload_file
  • create_bucket
  • list_bucket
  • authorize_account

Installation

    npm install --save blazer

Usage


const { authorize_account, createB2 } = require('blazer-b2');

/**
 * authorize_account is used to retrieve a b2 token which you can use
 * to create a b2Api via the b2 function. You can try to store this token once
 * retrieved an you can pass it to the b2 function to return an api
 */

//sample initialize to create a b2 Token

authorize_account(accountId, applicationKey).then ( token => {
    const b2 = createB2(token);

    //you can now use b2Api
    b2.upload_file(...);
    b2.create_bucket(...);

    //etc
});

Buckets

b2.create_bucket

Create a B2 Bucket. The required argument is bucketName and bucketType.
const bucketName = "myBucket";
const bucketType = "allPublic";

b2.create_bucket({bucketName, bucketType}).then( res => {
    console.log("bucket created ", res);
}).catch ( err => {
    console.log("error creating bucket");
});
You can also use it directly, without passing from the b2 instance.

const { buckets } = require('blazer-b2/buckets');
const { create_bucket } = buckets;

create_bucket(token)({bucketName, bucketType}).then( res => {
    console.log('bucket created ', res);
}).catch ( err => {
    console.log('error creating bucket');
});

b2.list_bucket

Upload

b2.get_upload_url

b2.upload

B2 Session

You can use the createB2 function to manually call a b2 api but if you use blazer from some sort of a server app, then it would be convenient to have some facility to help you do automatic retries and token keys management. The createB2Session calls does that exactly.

createB2Session

To create a b2Session object, call createB2Session passing in your accountId and applicationKey

    const { createB2Session } = require('blazer-b2');

    const b2Session = createB2Session( { accountId, applicationKey} );

    //use the api normally, b2session will automatically create token and
    //retry if needed
    b2Session.create_bucket(..)

configuration

The second argument to createB2Session is a config file with the following attribute

debug

if set to true, then more verbose log is outputted.

maxRetry

the maximum number of calls when there is a failure before giving up.

store

The store instance to use. By default it uses a memory store. You can pass your own store object which is required to have the following attributes.

token

A function that returns the current token object.

persistToken

A function that accepts the newToken object and returns a promise which gets resolved once the token has been persisted by the store.

invalidate

Invalidate the current active token. You need to set it to undefined such that calls to token() will return falsy.

A sample implementation below

const createMemoryStore = () => {
    var token;

    return {
        token() {
            return token;
        },
        persistToken(newToken) {
            token = newToken;
            return Promise.resolve(newToken);
        },
        invalidate() {
            token = undefined;
        }
    };
};

Status

| Api Call | Status | | --------------- |:-------------:| | create_bucket | done | | list_buckets | done | | upload_file | done | | authorized_account | done | | get_upload_url | done | | cancel_large_file | pending | | delete_bucket | done | | delete_file_version | done | | download_file_by_id | pending | | download_file_by_name | pending | | finish_large_file | pending | | get_file_info | done | | get_upload_part_url | pending | | hide_file | done | | list_file_names | done | | list_file_versions | done | | list_parts | pending | | list_unfinished_large_files | pending | | start_large_file | pending | | update_bucket | done | | upload_part | pending |

Requirements

Node 5+ is required at the moment.

Testing

npm run test

FAQ

If I need to pass the b2 functions, do I need to bind them to b2?

No. Functions on the B2 object are not dependent on the this context. You will be able to pass the member around without worrying on binding b2

someHandler( b2.create_bucket.bind(b2) ) //<--- you don't need to do this
someHandler( b2.create_bucket ); //<-- works fine