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

@gradient/blob-storage

v1.0.6

Published

A storage plugable api for persisting data to a data store

Downloads

16

Readme

Blob Storage

CircleCI

Blob storage at your finger tips

Blob storage can be awkward to orchestrate, especially when you need to switch out providers for your project on demand. Blob storage makes this easier, it comes pre-bundled with a number of pre-configured providers. Blob storage is opinionated and designed to work with minimal fuss and configuration.

Installation

NPM

$ npm i @gradient/blob-storage --save

Yarn

$ yarn add @gradient/blob-storage --save

Usage

Blob Storage currently supports the following clients:

  • Local storage (a disk volume your process has access to)
  • AWS S3

For implementation details of each client see the Specific clients section.

Initialisation

Initialising a local blob storage object:

const getBlobStore = require('@gradient/blob-storage');

const options = {
    provider: 'local',
    settings: {
        storageLocation: path.join(__dirname, '/tmp')
    }
};

const store = getBlobStore(options);

Initialising an S3 blob storage object:

const getBlobStore = require('@gradient/blob-storage');

const options = {
    provider: 's3',
    settings: {
        accessKeyId: 'your-iam-access-key',
        secretAccessKey: 'your-iam-secret-access-key'
    }
};

const store = getBlobStore(options);

Using the blob store

All blob storage clients meet the same interface, however some clients may not have implemented all the functions if they are irrelevant. The functions provided by the clients are:

getItem(key, locationId, itemType)

Gets an existing item.

  • key - is the blob identifier.
  • locationId - corresponds to some location identifier on the particular provider, for the local client this is a sub directory, for s3 this is a bucket, etc.
  • itemType (optional) - is another way to divide up the storage of your blobs. For instance, you may wish to separate user "avatars" which are images, from "podcast-episodes" which are sound files.

The return value is dependant on the implementation, usually it is a buffer of the file of something similar.

getMultipleItems(items, attempts)

Gets multiple existing items.

  • items - An array of objects with the attributes key, locationId, and itemType for the same purposes as the getItem function.
  • attempts (optional) - This is the number of attempts the client should make should it fail to get any item. By default this is usually 1, but will depend on the clients implementation.

The return value is dependant on the clients implementation, usually this is an array of file buffers or similar.

setItem(key, filePath, locationId, itemType)

Sets a new or existing item to a new blob (if this is a service based provider such as S3, this will upload the file).

  • key - is the blob name that it will be stored with and will be used to help identify it via other functions. This often corresponds to a file name on the particular system.
  • filePath - the full path to the file you wish to set (upload)
  • locationId - corresponds to some location identifier on the particular provider, for the local client this is a sub directory, for s3 this is a bucket, etc.
  • itemType (optional) - is another way to divide up the storage of your blobs. For instance, you may wish to separate user "avatars" which are images, from "podcast-episodes" which are sound files.

The return value is dependant on the clients implementation, usually this is a full URL or path to the blob.

deleteItem(key, locationId, itemType)

Deletes the item from the blob store.

  • key - is the blob identifier.
  • locationId - corresponds to some location identifier on the particular provider, for the local client this is a sub directory, for s3 this is a bucket, etc.
  • itemType (optional) - is another way to divide up the storage of your blobs. For instance, you may wish to separate user "avatars" which are images, from "podcast-episodes" which are sound files.

This often returns void, but this will depend on the clients implementation.

Specific clients

Local

Local storage makes use of an accessible local storage that the process has access to.

Only setItem and deleteItem have been implemented for this as setItem will return the full file path to the item.

AWS S3

Uses AWS's S3 (Simple Storage Solution) to store blobs.

Only setItem and deleteItem have been implemented for this as setItem will return the S3 location (a url) of the item for reading.

Contributions

We welcome contributions, if you'd like to create a new client implementation or complete an existing one, please submit a GitHub Pull Request. Please ensure you've written tests to check your changes.

We use yarn for this project, please ensure new packages are added using yarn so that it updates the yarn.lock file.

To run the tests, simply use yarn test!

To generate a build, run yarn build.

Licence

MIT @ Gradient Limited

Code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.