Home

Awesome

Notice: Development on this repository is currently on pause during our v3 rearchitecture. Please see storj/storj for ongoing v3 development.

node-libstorj

Storj.io Build Status npm version Chat on rocket.chat

Node.js library for encrypted file transfer on the Storj network via bindings to libstorj.

Example Usage

Install via npm:

npm install github:storj/node-libstorj --save

Please see ./examples directory for example code usage.

First setup the storj environment with authentication and encryption options:

const { Environment } = require('storj');

const storj = new Environment({
  bridgeUrl: 'https://api.storj.io',
  bridgeUser: 'user@domain.com',
  bridgePass: 'password',
  encryptionKey: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
  logLevel: 4
});

The encryptionKey is a randomly generated key used for file encryption, new keys can be randomly generated with the mnemonicGenerate method. The bridgeUrl, bridgeUser and bridgePass are the user credentials for authenticating to a Storj bridge.

Upload a file to a bucket:

const bucketId = '368be0816766b28fd5f43af5';
const filePath = './storj-test-upload.data';

const state = storj.storeFile(bucketId, filePath, {
  filename: 'storj-test-upload.data',
  progressCallback: function(progress, downloadedBytes, totalBytes) {
    console.log('progress:', progress);
  },
  finishedCallback: function(err, fileId) {
    if (err) {
      return console.error(err);
    }
    console.log('File complete:', fileId);
  }
});

Download a file from a bucket:

const bucketId = '368be0816766b28fd5f43af5';
const fileId = '998960317b6725a3f8080c2b';
const downloadFilePath = './storj-test-download.data';

const state = storj.resolveFile(bucketId, fileId, downloadFilePath, {
  progressCallback: function(progress, downloadedBytes, totalBytes) {
    console.log('progress:', progress)
  },
  finishedCallback: function(err) {
    if (err) {
      return console.error(err);
    }
    console.log('File download complete');
  }
});

Once finished, you should call to zero and free memory holding encryption keys:

storj.destroy();

Please see ./examples directory for further usage.

API

Methods available on an instance of Environment:

Development & Testing

If you do not already have libstorj installed on your system, you can install from the directions at https://github.com/Storj/libstorj This isn't required, however it's best for development.

If you do not have node-gyp installed:

$ npm install -g node-gyp

To build:

$ npm install
$ node-gyp build

To test:

$ npm run test

To test with gdb for debugging:

$ gdb --args node node_modules/.bin/_mocha -R spec test/index.test.js

License

Copyright (C) 2017 Storj Labs, Inc

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.