npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multidat

v5.1.1

Published

Manage multiple dat instances

Downloads

36

Readme

deprecated

More info on active projects and modules at dat-ecosystem.org


multidat

npm version build status test coverage downloads js-standard-style

Manage multiple dat instances in multiple locations.

Usage

var Multidat = require('multidat')
var toilet = require('toiletdb')

var db = toilet('/tmp/dat')
Multidat(db, function (err, multidat) {
  if (err) throw err

  multidat.create(opts, function (err, dat) {
    if (err) throw err

    var dats = multidat.list()
    console.log(dats)

    multidat.close(dat.archive.key, function (err) {
      if (err) throw err
      console.log()
    })
  })
})

Error handling

If there is an error initializing a dat, instead of the whole process failing, an error object with attached .dir property will be pushed into the list of dats instead. That means when consuming multidat.list(), you should check for errors:

var dats = multidat.list()
dats.forEach(function (dat) {
  if (dat instanceof Error) {
    var err = dat
    console.log('failed to initialize dat in %s: %s', err.dir, err.message)
  }
})

This way you can decide for yourself whether an individual initialization failure should cause the whole process to fail or not.

API

Multidat(db, opts, callback(err, multidat))

Creat a new Multidat instance. Takes a toiletdb instance and a callback.

Options:

  • Dat: Use provided dat factory instead of dat-node

multidat.create(dir, opts, callback(err, dat))

Create a new dat archive.

dats = multidat.list()

List all available dat archives.

multidat.close(key, callback(err))

Close and remove a dat archive.

multidat.readManifest(dat, callback(err, manifest))

Read the dat.json file from the dat archive. This method is expected to be deprecated once dat archives provide a built-in method to return archives.

Why?

This package exists to manage multiple dat archives in different directories. The dat-node package is mostly stateless; all state is persisted into the archives themselves. This package acts as a layer on top to keep track of where archives are located and manage them between sessions.

When not to use this

If you're running a server, it's usually enough to run mafintosh/hypercore-archiver which is more consistent and simpler. If you're building a tool that only needs to manage a single dat archive at the time it's recommended to use datproject/dat-node instead.

See Also

License

MIT