Code Monkey home page Code Monkey logo

tiny-storage-client's Introduction

Tiny client for distributed S3/Swift storages

GitHub release (latest by date) Documentation

High availability, Performances, and Simplicity are the main focus of this tiny Node client to request AWS S3 API or the OpenStack Swift Object Storage API. It was initially made to request OVHCloud, but it can be used for any Server/Cloud provider.

Highlights

  • ๐Ÿฆ„ Simple to use - Only 10 methods: uploadFile, downloadFile, deleteFile, listFiles, listBuckets, headBucket, setFileMetadata, getFileMetadata, deleteFiles and request for custom requests.
  • ๐Ÿš€ Performances - Vanilla JS + Only 2 dependencies rock-req as HTTP client and aws4 for signing S3 requests.
  • ๐ŸŒŽ High availability - Provide one or a list of storages credentials: the SDK will switch storage if something goes wrong (Server/DNS not responding, timeout, error 500, too many redirection, authentication error, and more...). As soon as the main storage is available, the SDK returns to the main storage
  • โœจ Reconnect automatically - If a request fails due to an authentication token expiration, the SDK fetches a new authentication token and retry the initial request with it (Concerns only Swift Storage).
  • โœ… 100% tested - Production battle-tested against hundreds of TBs of file uploads, downloads and deletes
  • ๐Ÿ‘‰ Convert XML/JSON responses to JS - XML/JSON responses are automatically converted into Objects/Arrays (Concerns only: listFiles, listBuckets and Errors).
  • ๐Ÿšฉ Mixing S3 and Swift credentials is not supported - When initialising the Tiny SDK client, provide only a list of S3 or a list of Swift credentials, switching from one storage system to another is not supported.

Getting Start

Install and setup in less than 2 minutes:

Supported Methods

Swift API S3 API Method Description
โœ… example โœ… example uploadFile Upload a file from a Buffer or file absolute path.
โœ… example โœ… example downloadFile Download a file as Buffer or Stream
โœ… example โœ… example deleteFile Delete a file
โœ… example โœ… example deleteFiles Bulk delete files (1000 max/per request)
โœ… example โœ… example listFiles List files (1000 max/per requests) use query parameters for pagination
โœ… example โœ… example getFileMetadata Fetch custom metadatas
โœ… example โœ… example setFileMetadata Set custom file metadatas
โœ… example โœ… example headBucket Determine if a bucket exists and you have permission to access it
โœ… example โœ… example listBuckets Returns a list of all buckets owned by the authenticated sender of the request.
โœ… example โœ… example request Create custom requests
โœ… example โŒ connection Connection is required only for Openstack Swift Object storage to get a unique auth token
โœ… example โœ… example Bucket Alias Simplify requests by using bucket alias

S3 Example

The following exemple is an initialisation of the SDK client with a list of S3 credentials and a request to download a file. If something goes wrong when downloading the file, the SDK will switch storage and retry to download with the second credentials. As soon as the first storage is available, the SDK returns to the main storage

const storageClient = require('tiny-storage-client');

const s3storage = storageClient([{
    accessKeyId    : 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    url            : 's3.gra.io.cloud.ovh.net',
    region         : 'gra'
  },
  {
    accessKeyId    : 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    url            : 's3.eu-west-3.amazonaws.com',
    region         : 'eu-west-3'
  }])

s3storage.downloadFile('bucketName', 'filename.pdf', (err, resp) => {
  if (err) {
    return console.log("Error on download: ", err);
  }
  /**
   * Request reponse:
   * - resp.body => downloaded file as Buffer
   * - resp.headers
   * - resp.statusCode
   */
})

Run tests

Install

$ npm install

To run all the tests:

$ npm run test

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a โญ๏ธ if this project helped you!

Supporters

This packaged in maintained by Carbone:

Carbone.io logo

tiny-storage-client's People

Contributors

steevepay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.