Code Monkey home page Code Monkey logo

backblaze's Introduction

backblaze's People

Contributors

franciscop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

backblaze's Issues

Allow large file uploads

We are using the https://www.npmjs.com/package/backblaze-b2 API behind this library, but making it more abstract and hopefully easier to manage your files with backblaze. This means to upload a file, you just need to do bucket.upload(localFileName), but so far it only works with normal files.

Feature request: allow bucket.upload(localFileName) to also accept large files for upload and use b2's APIs for that internally:

  • startLargeFile()
  • getUploadPartUrl()
  • uploadPart()
  • finishLargeFile()

You might want to check the file size prior to this with a fs.stat() to check the size first.

The API of bucket.upload(localFileName) should remain the same as much as possible, so when the end user does bucket.upload() they should not care whether it's a small or a large file.

Allow reading a remote file straight away

Let's say you have a data.json in your bucket and you want to read it. Right now you need to do:

await bucket.download('./data.json');
const raw = await fs.readFile('./data.json');
const data = JSON.parse(raw);

Feature request: create a new method called bucket.read(remoteFileName) that will read the remote file straight into a variable, so that the above can be simplified to this:

// Note it's now called `.read()`
const raw = await bucket.read('./data.json');
const data = JSON.parse(raw);

Tip: if it cannot be read directly, you can try using a temp directory to download the file and then read it.

Working with folders

Working with folders could/should be made easier. For this, I propose this API:

Simply define a folder to upload the file:

// Relative uncomplete path
await bucket.upload(myFile, '/profile/');
// Output: { name: "/profile/3nNLR9AUdgjRWrVd.png", ... }

// List the given folder
await bucket.list('/profile/');

// Maybe? Remove a full folder
await bucket.remove('/profile/');

// Maybe? Download a full folder
await bucket.download('/profile/');
// Will download into `./profile/`

Later on, a full namespace could be done, but for now I think it's best to do only the proposed above:

// Use it concatenating with a `.folder()`
bucket.folder('profile').upload(myFile);
// Output: `/profile/3nNLR9AUdgjRWrVd.png`

// Create a separated variable to handle it
const profileBucket = bucket.folder('profile');
profileBucket.upload(myFile);
// Output: `/profile/3nNLR9AUdgjRWrVd.png`

Allow piping data

Allow to pipe data to upload:

const bucket = Bucket();

// Option A:
fs.createReadStream('./demo.png')
  .pipe(bucket.upload)
  .on('end', file => {
    console.log(file);
  });

// Option B:
const file = await bucket.upload(fs.createReadStream('./demo.png'));

Note: I prefer option B if possible

Allow uploading into a folder

When uploading a file, it autogenerates the name of the file. Or you can specify the full path of the file to name. Both are fine, but it'd be nice if you could also specify the "folder" to upload and it still autogenerates the name. Example:

// Current way
bucket.upload(file.path);  // kwergvckwsdb.png

// Proposed alternative, a path ending with a slash to denote it's a folder,
// but still autogenerate the filename
bucket.upload(file.path, "profile/");  // profile/kwergvckwsdb.png

Restricting key to a single bucket fails

If you restrict the key generated to a single bucket, even if it's the one that you want, fails:

image

...
    data: { code: 'unauthorized', message: '', status: 401 }
...

Probably because of this line:

      const list = await b2.listBuckets();
      const raw = list.data.buckets.find((b) => b.bucketName === name);
      bucket = { ...raw, baseURL };

So we should find a new way of getting the current bucket info instead of relying picking the right one out of a global list.

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.