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

dat-librarian

v1.1.8-beta

Published

A dedicated Dat peer.

Downloads

29

Readme

DatLibrarian

Stability NPM Version JS Standard Style Build Status Coverage Status Greenkeeper badge

A dedicated Dat peer. Use DatLibrarian to store and peer many Dat archives. Similar to hypercore-archiver.

For example:

const DatLibrarian = require('dat-librarian')
const librarian = new DatLibrarian({ dir: '.dats' })
console.log(librarian.keys)
> [] // no known archives yet
librarian
  // load pre-existing archives
  .load()
  // promises!
  .then(() => {
    // use keys or links per dat-link-resolve
    return librarian.add('garbados.hashbase.io')
  })
  .then(() => {
    console.log(librarian.keys)
    > ['c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957']
  })

Install

Install DatLibrarian and its dependencies with npm:

npm i -S dat-librarian

Usage

Table of Contents

DatLibrarian is a dedicated Dat peer similar to hypercore-archiver that persists archives to disk and seeds them to the network.

Examples

const DatLibrarian = require('dat-librarian')
const librarian = new DatLibrarian({ dir: '.dats' })
librarian
  // load pre-existing archives
  .load()
  // promises!
  .then(() => {
    // use keys or links per dat-link-resolve
    return librarian.add('garbados.hashbase.io')
  })

DatLibrarian

Extends EventEmitter

Instantiate a new DatLibriarian.

Parameters

  • options Object Options object.
    • options.dir String The librarian's working directory, where it will cache archives. Required.
    • options.dat Object Options object passed to Dat()
    • options.net Object Options object passed to dat.joinNetwork()

load

Load Dat archives into cache by checking the working directory for existing archives.

Examples

librarian.load().then(() => {
  ...
})

Returns Promise<Array> A promise that resolves once any existing archives have been loaded into the cache.

get

Get an archive from the cache by link.

Parameters

Examples

librarian.get('garbados.hashbase.io').then((dat) => {
  ...
})

Returns Promise<Dat> Promise that resolves to a Dat archive.

add

Add an archive by link. Automatically joins the network and begins downloading, but does not wait for the archive to complete.

Parameters

Examples

librarian.add('garbados.hashbase.io').then((dat) => {
  ...
})

Returns Promise A promise that resolves once the archive has been added to the cache.

remove

Remove an archive from the cache and the working directory.

Parameters

Examples

librarian.remove('garbados.hashbase.io').then(() => {
  ...
})

Returns Promise A promise that resolves once the archive has been removed.

list

Lists the keys in the cache.

Examples

let keys = librarian.list()
console.log(keys)
> ['c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957']

Returns Array<String> An array of all the keys in the cache.

keys

Getter for the keys in the cache. Alias to #list()

Examples

console.log(librarian.keys)
> ['c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957']

Returns Array<String> An array of all the keys in the cache.

close

Close the librarian and any archives it is peering.

Examples

librarian.close().then(() => {
  ...
})

Returns Promise Promise that resolves once all archives have closed.

resolve

Promification of dat-link-resolve for convenience's sake.

Parameters

Examples

DatLibrarian.resolve('garbados.hashbase.io').then((key) => {
  console.log(key)
  > 'c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957'
})

Returns Promise<Buffer> Key of that Dat archive

join

Event emitted once an archive has completed its first round of peer discovery.

Examples

librarian.on('join', (dat) => {
  ...
})

add

Event emitted when an archive is added.

Examples

librarian.on('add', (dat) => {
  ...
})

remove

Event emitted once an archive has been removed.

Examples

librarian.on('remove', (link) => {
  ...
})

Development

Download the source and run the test suite:

git clone garbados/dat-librarian
cd dat-librarian
npm install
npm test

Contributions

All contributions are welcome: bug reports, feature requests, "why doesn't this work" questions, patches for fixes and features, etc. For all of the above, file an issue or submit a pull request.

License

Apache-2.0