cloud-bucket
Simple multi cloud (Google Storage and AWS S3) bucket API
Last updated 12 days ago by jeremychone .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cloud-bucket 
SYNC missed versions from official npm registry.

Simple cross cloud (for now GCP and AWS) bucket API.

Current Features:

  • Supports AWS, GCP.
  • Directory support (i.e. directory: true makes .dirs = string[])
  • Promise/async/await based.
  • signed url (with urlSigner supporting s3 wildcard signature)
  • Glob support (processed on the nodejs side)
  • Typed (Typescript)

Roadmap:

  • Stream copy between bucket
  • Azure support

Usage

  • npm install cloud-bucket
import {getBucket} from 'cloud-bucket';

const bucketCfg = {
  bucketName: '_BUCKET_NAME_'
  access_key_id: "_AWS_ACCESS_KEY_ID_"
  access_key_secret: "_AWS_ACCESS_KEY/_SECRET_"
};

const bucket = await getBucket(bucketCfg);

//// Uploads
const file = await bucket.getFile('/some-file.txt');
// Return BucketFile or null if not found, throws exception if other error.

// upload to a folder
const remoteFiles = await bucket.upload('./some-file.txt', 'in-this-folder/');
// [{Bucket:..., 
//  path: 'in-this-folder/some-file.txt', 
//  size: 34, // size in bytes
//  local: './some-file.txt' // only present for upload/download
//  }]

// will upload to a specific name
const remoteFiles = await bucket.upload('./some-file.txt', 'in-this-folder/new-name.txt');

// upload a full folder remotely (recursive)
const remoteFiles = await bucket.upload('./some-dir/', 'remote-base-dir/');


//// List

const files = await bucket.listFiles();
// files: File[] (all files contained in this bucket, no pagination yet)

const files = await bucket.listFiles('in-this-folder/', {limit: 300});
// files: File[] (only file with the prefix 'in-this-folder/) and only the first 300;

const files = await bucket.listFiles('in-this-folder/**/*.txt');
// files: File[] (only file with the prefix 'in-this-folder/ and matching the glob);
// Note: Glob processing happen on the nodejs side.

// More result info by calling the list method. 
const listResult = await bucket.list('in-this-folder/', {directory: true});
// {files: BucketFile[], dirs?: string[], nextMarker}


//// Download

const files = await bucket.download('in-this-folder/some-file.txt', './local-dir/');
// files: [{
//   Bucket:  ...,
//   path: 'in-this-folder/some-file.txt',
//   size: 34,
//   local: `./local-dir/some-file.txt'
// }]

const files = await bucket.download('in-this-folder/**/*.txt', './local-dir/');
// Note: When glob as src, then, sub folder from the base path will be added in the local-dir
// files: [{
//   Bucket:  ...,
//   path: 'in-this-folder/some-file.txt',
//   size: 34,
//   local: `./local-dir/some-file.txt'
// },{
//   Bucket:  ...,
//   path: 'in-this-folder/sub-dir/another-file.txt',
//   size: 34,
//   local: `./local-dir/sub-dir/another-file.txt'
// },
//]

const deleted = await bucket.delete('some-file.txt');
// return true if deleted, false if not found, throws exception if other error.

For Google Cloud Storage, just use (the getBucket API will auto-detect the type of cloud from the config object):

const bucketCfg = {
  bucketName: '_GOOGLE_BUCKET_NAME_',
  project_id: '_GOOGLE_PROJECT_ID_NAME_',
  client_email: '_GOOGLE_SERVICE_ACCOUNT_EMAIL_',
  private_key: '-----BEGIN PRIVATE KEY-----\n_GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY_WITH_NEW_LINE_\n-----END PRIVATE KEY-----'
}

Current Tags

  • 0.3.0                                ...           latest (12 days ago)

18 Versions

  • 0.3.0                                ...           12 days ago
  • 0.2.16                                ...           2 months ago
  • 0.2.15                                ...           2 months ago
  • 0.2.14                                ...           3 months ago
  • 0.2.13                                ...           5 months ago
  • 0.2.12                                ...           7 months ago
  • 0.2.11                                ...           7 months ago
  • 0.2.10                                ...           7 months ago
  • 0.2.8                                ...           8 months ago
  • 0.2.7                                ...           10 months ago
  • 0.2.6                                ...           a year ago
  • 0.2.5                                ...           a year ago
  • 0.2.4                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
Maintainers (1)
Downloads
Today 26
This Week 54
This Month 54
Last Day 28
Last Week 117
Last Month 720
Dependencies (7)
Dev Dependencies (6)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |