Skip to content

About

A storage abstraction layer for Node.js that removes any difference among multiple public cloud storage services and local filesystems

Topics

Resources

Security policy

Stars

17 stars

Watchers

1 watching

Forks

Repository files navigation



fox1t_disco_elysium_styled_storagebus_with_boxes_covered_by_clo_8b9e8a49-f59c-44a6-9c6e-58bdedc9ee3f

CI Test Coverage Status Maintainability storage local memory gcs s3 All Contributors

StorageBus is a storage abstraction layer for Node.js that removes differences among public cloud storage services, local filesystems, and in-memory storage.

Usage

StorageBus v1 has two core operations:

  • write(objectKey, data) writes, replaces, or deletes an object.
  • file(objectKey) returns a BusFile, which can stream content and expose metadata.

You can use StorageBus with your filesystem, AWS S3, Google Cloud Storage, or memory:

import { Readable } from 'node:stream'
import { Storage } from '@storagebus/storage'
import { createAdapter } from '@storagebus/local'

const storage = new Storage(createAdapter({ root: '/path/to/folder' }))

async function main() {
  const objectKey = await storage.write('hello.txt', 'Hello, world!')
  const file = await storage.file(objectKey)

  console.log(file.name)
  console.log(file.type)
  console.log(file.size)
  console.log(await file.text())

  await storage.write('stream.txt', () => Readable.from('stream content'))

  // Passing null deletes the Object Key.
  await storage.write('hello.txt', null)
}

Packages

  • @storagebus/storage: core Storage, BusFile, Adapter contract, shared errors, and compliance tests.
  • @storagebus/memory: in-memory Adapter.
  • @storagebus/local: local filesystem Adapter.
  • @storagebus/s3: AWS S3 Adapter.
  • @storagebus/gcs: Google Cloud Storage Adapter.

Migration to v1

StorageBus v1 creates Storage from the core package and injects an Adapter from the target Storage Backend package.

Before v1:

import { createStorage } from '@storagebus/local'

const storage = createStorage({ root: '/path/to/folder' })

In v1:

import { Storage } from '@storagebus/storage'
import { createAdapter } from '@storagebus/local'

const storage = new Storage(createAdapter({ root: '/path/to/folder' }))

Storage options such as debug, logger, and sanitizeKey now belong to Storage, not Adapter packages:

const storage = new Storage(createAdapter({ root: '/path/to/folder' }), {
  sanitizeKey: true,
})

Contribute to this project

  1. Clone this repository

    git clone git@github.com:github.com/ducktors/storagebus.git

  2. Move inside repository folder

    cd storagebus

  3. Install dependencies

    pnpm install

  4. Run the project in development mode

    pnpm dev

How to release

The release is performed by the maintainers of the repository. New versions are managed via changesets.

To release a new version, simply choose which package to bump with pnpm release command:

$ pnpm release

> storagebus@0.9.0 release /ducktors-workstation/storagebus
> changeset

🦋  Which packages would you like to include? …
◯ unchanged packages
  ◯ @storagebus/storage
  ◯ @storagebus/gcs
  ◯ @storagebus/local
  ◯ @storagebus/s3

Contributors

Maksim Sinik
Maksim Sinik

💻 ⚠️ 🤔 🚧 🧑‍🏫
Matteo Vivona
Matteo Vivona

🚇 🛡️ 📖
Andrew Hu
Andrew Hu

📖
Alessandro Di Dio
Alessandro Di Dio

💻

About

A storage abstraction layer for Node.js that removes any difference among multiple public cloud storage services and local filesystems

Topics

Resources

Security policy

Stars

17 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages