@stacks/storage
Stacks storage library
Last updated a month ago by reedrosenbluth .
GPL-3.0-or-later · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @stacks/storage 
SYNC missed versions from official npm registry.

@stacks/storage

Store and fetch files with Gaia, the decentralized storage system.

Installation

npm install @stacks/storage

Usage

Initiating a storage client

import { UserSession } from '@stacks/auth';
import { Storage } from '@stacks/storage';

const appConfig = new AppConfig();
const userSession = new UserSession({ appConfig });
const storage = new Storage({ userSession });

Note that you can also use an existing userSession object created during the authentication process.

Put file

const myData = JSON.stringify({
  hello: "world",
  num: 1
});

storage.putFile('my_data.json', myData));

Store data at a different path

storage.putFile('path/my_data.json', myData));

Put file with options

const putFileOptions = {
  // override the default content type
  contentType: 'application/json', 
  // override encrypting data by default
  // you can also set encrypt to a private key to specify a custom encryption key
  encrypt: false, 
  // ignore automatic conflict prevention using etags
  dangerouslyIgnoreEtag: true
}

storage.putFile('my_data.json', myData, putFileOptions));

Get file

storage.getFile('my_data.json').then((fileContent) => {
  console.log(fileContent);
});

Get file with options

const getFileOptions = {
  decrypt: false,
  // by default files stored are signed and can be verified for authenticity
  verify: false
}

storage.getFile('my_data.json', getFileOptions).then((fileContent) => {
  console.log(fileContent);
});

Delete file

storage.deleteFile('my_data.json');

Delete the file and the corresponding signature file if signed

storage.deleteFile('my_data.json', { wasSigned: true });

List file

List all files in the user's Gaia hub

storage.listFiles((filename) => {
  if (filename === 'my_data.json') {
    return storage.getFile(filename).then((fileContent) => {
      console.log(fileContent);
      // return false to stop iterating through files
      return false;
    })
  } else {
    // return true to continue iterating
    return true;
  }
});

Current Tags

  • 1.5.0-alpha.1                                ...           alpha (5 months ago)
  • 1.0.0-beta.8                                ...           beta (a year ago)
  • 2.0.1                                ...           latest (a month ago)

41 Versions

  • 2.0.1                                ...           a month ago
  • 2.0.1-beta.2                                ...           2 months ago
  • 2.0.1-beta.1                                ...           2 months ago
  • 3.0.0-beta.0 [deprecated]           ...           2 months ago
  • 2.0.0 [deprecated]           ...           2 months ago
  • 2.0.0-beta.1                                ...           4 months ago
  • 2.0.0-beta.0                                ...           4 months ago
  • 1.5.0-alpha.1                                ...           5 months ago
  • 1.5.0-alpha.0                                ...           5 months ago
  • 1.3.3                                ...           6 months ago
  • 1.2.3                                ...           7 months ago
  • 1.2.2                                ...           7 months ago
  • 1.2.2-alpha.0                                ...           7 months ago
  • 1.2.1-alpha.0                                ...           7 months ago
  • 1.2.0                                ...           7 months ago
  • 1.1.1-alpha.0                                ...           8 months ago
  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
  • 1.0.0-beta.20                                ...           9 months ago
  • 1.0.0-beta.19                                ...           10 months ago
  • 1.0.0-alpha.19                                ...           10 months ago
  • 1.0.0-beta.18                                ...           10 months ago
  • 1.0.0-beta.17                                ...           10 months ago
  • 1.0.0-beta.16                                ...           10 months ago
  • 1.0.0-beta.15                                ...           10 months ago
  • 1.0.0-beta.14                                ...           10 months ago
  • 1.0.0-beta.13                                ...           10 months ago
  • 1.0.0-beta.12                                ...           10 months ago
  • 1.0.0-beta.11                                ...           10 months ago
  • 1.0.0-beta.10                                ...           10 months ago
  • 1.0.0-alpha.9                                ...           10 months ago
  • 1.0.0-beta.9                                ...           a year ago
  • 1.0.0-beta.8                                ...           a year ago
  • 1.0.0-beta.7                                ...           a year ago
  • 1.0.0-beta.6                                ...           a year ago
  • 1.0.0-beta.5                                ...           a year ago
  • 1.0.0-beta.4                                ...           a year ago
  • 1.0.0-beta.3                                ...           a year ago
  • 1.0.0-beta.2                                ...           a year ago
  • 1.0.0-beta.1                                ...           a year ago
Downloads
Today 3
This Week 10
This Month 107
Last Day 3
Last Week 26
Last Month 151
Dependencies (5)
Dev Dependencies (12)

Copyright 2014 - 2017 © taobao.org |