Simple Swarm interface to swarm-gateways.net (or other gateways)
Go to file
emizzle ced4d82c2d Refactor to class and add `putDirectory`
Refactored the module to export a class, which can now be invoked using `new SwarmGW()`

Added a `putDirectory` function that walks a directory, finds all files recursively, and uploads them to swarm expecting a manifest hash in return.
2018-08-16 20:16:39 +10:00
.gitignore Include .gitignore 2016-12-04 23:11:09 +00:00
LICENSE Initial version 2016-12-04 22:47:15 +00:00
README.md Better API 2018-08-09 12:08:24 +01:00
index.js Refactor to class and add `putDirectory` 2018-08-16 20:16:39 +10:00
package-lock.json Refactor to class and add `putDirectory` 2018-08-16 20:16:39 +10:00
package.json Refactor to class and add `putDirectory` 2018-08-16 20:16:39 +10:00
swarmgw Better API 2018-08-09 12:08:24 +01:00

README.md

swarmgw

This library can be used to upload/download files to Swarm via https://swarm-gateways.net/ (or an optionally provided gateway).

Note that while this is a convenient feature as of today, it may not be present indefinitely.

Library usage

const swarmgw = require('swarmgw')(/* opts */)

// This should output the hash: 931cc5a6bd57724ffd1adefc0ea6b4f0235497fca9e4f9ae4029476bcb51a8c6
swarmgw.put('Hello from swarmgw!', function (err, ret) {
  if (err) {
    console.log('Failed to upload: ' + err)
  } else {
    console.log('Swarm hash: ' + ret)
  }
})

// This should output the content: Hello from swarmgw!
swarmgw.get('bzz-raw://931cc5a6bd57724ffd1adefc0ea6b4f0235497fca9e4f9ae4029476bcb51a8c6', function (err, ret) {
  if (err) {
    abort('Failed to download: ' + err)
  } else {
    console.log(ret)
  }
})

The opts above is a map of options:

  • gateway: supply your own gateway URL, if not provided, it will use "swarm-gateways.net"
  • mode: can be http or https (default is https), ignore if gateway is provided

CLI usage

It can also be used via the command line if installed globally (npm install -g swarmgw). To see the help: swarmgw --help.

License

MIT License

Copyright (C) 2016 Alex Beregszaszi