New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dat-node

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dat-node

Share datasets on the Internet

  • 1.0.0-alpha-2.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
121
decreased by-6.92%
Maintainers
1
Weekly downloads
 
Created
Source

dat-node 1.0 alpha Travis

Node module for Dat (replaces dat-js).

Create Dat Archives with a .dat folder. Join the Dat Network. Track stats and import files.

Features

Usage

Use to create or read Dat Archives on the file system in Node applications.

var Dat = require('dat-node')

Dat(dir, opts, function (err, dat) {
  console.log(dat.path) // dat is created here with a .dat folder

  var db = dat.db // level db in .dat folder
  var archive = dat.archive // hyperdrive archive

  // Join the network
  var network = dat.joinNetwork(opts)
  network.swarm // hyperdrive-archive-swarm

  // Track stats
  var stats = dat.trackStats() // hyperdrive-stats

  // Import Files
  if (archive.owner) {
    var importer = dat.importFiles(opts, cb) // hyperdrive-count-import
  }
})

Moving from dat-js:

Archives are created with a callback function. Once the archive is created, you can join the network directly without choosing to share or download. If the user owns the archive, they will be able to import files.

Sharing

For example, previously to share files with dat-js we would write:

// dat-js OLD API
var dat = Dat({dir: dir})
dat.share(function () {
   // automatically import files
   // automatically join network
  console.log('now sharing:', dat.key.toString())
})

In dat-node this would be:

// dat-node v1 NEW API
Dat(dir, function (err, dat) {
  var network = dat.joinNetwork(opts) // join network
  console.log('now sharing:', dat.key.toString())

  // import files
  var importer = dat.importFiles(opts, function () {
    console.log('done importing files')
  })

  // get stats info (via hyperdrive-stats)
  var stats = dat.trackStats()
})
Downloading

Previously to download files with dat-js we would write:

// dat-js OLD API
var dat = Dat({dir: dir, key: link})
dat.download()
console.log('downloading...')

In dat-node this would be:

// dat-node v1 NEW API
Dat(dir, {key: link}, function (err, dat) {
  var network = dat.joinNetwork(opts) // join network
  console.log('now downloading')

  var stats = dat.trackStats() // get hyperdrive-stats info
})

API

`Dat(dir, [opts], cb)``

Initialize a Dat Archive in dir. If there is an existing Dat Archive, the archive will be resumed.

Initial opts can include:

opts = {
  db: level(path/.dat), // level-db compatible database
  key: '<dat-key>', // existing key to create archive with or resume
  resume: Boolean, // fail if existing archive differs from opts.key

  // Hyperdrive archive options
  live: Boolean, // archive.live setting (only set if archive is owned)
  file: raf(), // file option for hyperdrive.createArchive()

  // dat-folder-db options
  dbName: '.dat' // directory name for level database
}

The callback includes a dat object that has the following properties:

dat.archive

Hyperdrive archive instance.

dat.db

.dat folder database

dat.path

Path of the Dat Archive

dat-node provides an easy interface to common Dat modules for the created Dat Archive on the dat object provided in the callback:

var network = dat.joinNetwork([opts])

Join the Dat Network for your Dat Archive.

opts are passed to the swarm module. See hyperdrive-archive-swarm for options.

network.swarm

discovery-swarm instance.

network.peers()

Get number of peers connected to you.

var importer = dat.importFiles([opts], [cb])

(must be the archive owner)

Import files to your Dat Archive from the directory using hyperdrive-import-files. Options are passed to the importer module. cb is called when import is finished.

dat-node provides a default ignore option, ignoring the .dat folder and all hidden files or directories.

Returns the importer event emitter.

var stats = dat.trackStats()

hyperdrive-stats instance for the Dat Archive. Stats are stored in a sublevel database in the .dat folder.

Transfer speeds are tracked using hyperdrive-network-speed and exposed to stats.network..

stats.network

Get upload and download speeds: stats.network.uploadSpeed or stats.network.downloadSpeed.

Keywords

FAQs

Package last updated on 10 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc