rubik-file-fs

1.0.0-beta.1 • Public • Published

Rubik's File system provider for File Kubik

Using

This module is rather a demo. It is not the most optimal, and is written to show an example of a Provider for the rubik-file module.

Anyway, it can be used in small projects. As always at your own fear and risk.

Install rubik-main, rubik-file and rubik-file-fs modules

Via Yarn

yarn add rubik-main rubik-file rubik-file-fs

Via NPM

npm i rubik-main rubik-file rubik-file-fs

Create config directory and file.js file in it

module.exports = {
  provider: 'FS',
  FS: {
    // This is the path to a folder where files will be stored
    storageDir: path.join(__dirname, '../files')
  }
};

Create an application, add config kubik and file kubik

const path = require('path');
const { App, Kubiks } = require('rubik-main');
const File = require('rubik-file');

const app = new App();
app.add([
  // First argument is a directory with configs
  new Config(path.join('./config/')),
  new File()
]);

Add the FSProvider constructor

const FSProvider = require('rubik-file-fs');
//...
app.file.addProvider('FS', FSProvider);

Up the application

app.up().
then(() => {}).
catch((err) => {
  console.error(err);
  process.exit(1);
});

Write your fist file

app.up().
then(async () => {
  const readStream = fs.createReadStream(
    path.join(__dirname, './some-file.txt')
  );
  await app.file.write({
    key: 'some-file.txt',
    bucket: 'some-bucket'
  }, readStream);
}).
catch((err) => {
  console.error(err);
  process.exit(1);
});

/rubik-file-fs/

    Package Sidebar

    Install

    npm i rubik-file-fs

    Weekly Downloads

    0

    Version

    1.0.0-beta.1

    License

    Apache-2.0

    Unpacked Size

    26.1 kB

    Total Files

    23

    Last publish

    Collaborators

    • ya-kostik