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

@smcloudstore/backblaze-b2

v0.2.1

Published

Backblaze B2 library for SMCloudStore

Downloads

8

Readme

@smcloudstore/backblaze-b2

This package is a provider for SMCloudStore, for Backblaze B2. SMCloudStore is a lightweight Node.js module that offers a simple API to interact with the object storage services of multiple cloud providers.

Please refer to the main package for the SMCloudStore documentation and instructions on how to use it.

System requirements

The Backblaze B2 provider requires Node.js version 10 or higher.

Provider-specific considerations

There are a few provider-specific considerations for the BackblazeB2 provider.

Connection argument

When initializing the BackblazeB2 provider, the connection argument is an object with:

  • connection.accountId: string containing the account ID (the "public key")
  • connection.applicationKey: string containing the application key (the "secret key"). Since this provides uses version 2 of the Backblaze B2 APIs, the key could be either the "master application key" or a "normal application key"; for more information, please refer to the B2 documentation.

Example:

// Require the package
const SMCloudStore = require('smcloudstore')

// Complete with the connection options for Backblaze B2
const connection = {
    accountId: 'ACCOUNT_ID_HERE',
    applicationKey: 'APPLICATION_KEY_HERE'
}

// Return an instance of the BackblazeB2Provider class
const storage = SMCloudStore.create('backblaze-b2', connection)

Creating a container

When using the storage.createContainer(container, [options]) and the storage.ensureContainer(container, [options]) methods, the options argument can be used to define some options for the container:

  • options.access (optional): string determining the permission for all objects inside the container; possible values are:
    • 'public'
    • 'private'

Uploading an object

The Backblaze B2 APIs have relatively poor support for streams, as it requires the size of the data to be sent at the beginning of the upload request. Because of that, the Backblaze B2 provider can operate in two separate modes when uploading files:

  1. If the length of the data can be known before the upload starts, the provider makes a single upload call. This applies to all situations when data is a Buffer or a string, and when data is a Stream and either the options.length argument is specified (see below), or data.byteLength is defined (all data is loaded in memory before being sent to the server in this case).
  2. In the situation when data is a Stream and the length can't be known beforehand, if the data is longer than B2Upload.chunkSize (default: 9MB; minimum: 5MB) the method will use B2's large files APIs. With those, it's possible to chunk the file into many chunks and upload them separately, thus it's not necessary to load the entire Stream in memory. However, this way of uploading files requires many more network calls, and could be significantly slower. B2 supports up to 1,000 chunks per object, so using 9MB chunks (the default value for B2Upload.chunkSize), maximum file size is 90GB.

Note: There is currently an issue with an upstream package that limits B2Upload.chunkSize to be no more than 10MB.

With the Backblaze B2 provider, the storage.putObject(container, path, data, [options]) method comes with an extra key for the options dictionary, in addition to the standard options.metadata key:

  • options.length (optional): as described above, when data is a Stream, if the length of the stream can be known in advance, setting options.length with the byte size (or the byteLength property in the data object directly) allows the BackblazeB2 provider to upload the object with a single call. This option is ignored if data is a string or Buffer.

Using pre-signed URLs

Backblaze B2 does not support pre-signed URLs, which are not available in their APIs. Because of that, the methods presignedGetUrl and presignedPutUrl always throw an exception when called on the BackblazeB2 provider.

Accessing the Backblaze B2 library

The AWS S3 provider is built on top of backblaze-b2, which is exposed by calling storage.client().

You can use the object returned by this method to perform low-level operations using the backblaze-b2 module.