storj

Node.js library for encrypted file transfer on the Storj network.

node-libstorj

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 ./examplesdirectory 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
});

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 ./examplesdirectory for further usage.

API

  • .Environment(options)- A constructor for keeping encryption options and other environment settings, see available methods below
  • .mnemonicGenerate(bits)- Will create a new Encryption Keystring for file encryption/decryption
  • .mnemonicCheck(encryptionKey)- Will return boolean to verify that an Encryption Keyhasn't been typed incorrectly by verifying the checksum and format
  • .utilTimestamp()- Returns current unix timestamp in milliseconds

Methods available on an instance of Environment:

  • .getInfo(function(err, result) {})- Gets general API info`
  • .getBuckets(function(err, result) {})- Gets list of available buckets
  • .createBucket(bucketName, function(err, result) {})- Creates a bucket
  • .deleteBucket(bucketId, function(err, result) {})- Deletes a bucket
  • .listFiles(bucketId, function(err, result) {})- List files in a bucket
  • .storeFile(bucketId, filePath, options)- Uploads a file, returns state object
  • .storeFileCancel(state)- This will cancel an upload
  • .resolveFile(bucketId, fileId, filePath, options)- Downloads a file, return state object
  • .resolveFileCancel(state)- This will cancel a download
  • .deleteFile(bucketId, fileId, function(err, result) {})- Deletes a file from a bucket
  • .destroy()- This will zero and free memory of encryption keys and the environment

Development & Testing

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

If you do not have node-gypinstalled:

$ 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/.

HomePage

https://github.com/storj/node-libstorj#readme

Repository

https+https://github.com/storj/node-libstorj


上一篇:storj-express
下一篇:deaddrop-core

相关推荐

  • storjshare-daemon

    daemon process manager for sharing space on the storj network Storj Share Daemon =================...

    7 个月前
  • storj-service-storage-models

    common storage models for various storj services Storj Service Storage Models =====================...

    7 个月前
  • storj-service-error-types

    common error types for various storj services Storj Service Error Types ========================= ...

    7 个月前
  • storj-express

    express middleware that exposes a configurable storj endpoint on an express server storjexpress ===...

    7 个月前
  • storj-admin-cli

    command line program for performing manual admin tasks at Storj Storj Admin CLI =============== A ...

    7 个月前

官方社区

扫码加入 JavaScript 社区