DatLibrarian
A dedicated Dat peer. Use DatLibrarian to store and peer many Dat archives. Similar to hypercore-archiver.
For example:
const DatLibrarian = const librarian = dir: '.dats' console> // no known archives yetlibrarian // load pre-existing archives // promises!
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 = const librarian = dir: '.dats' librarian // load pre-existing archives // promises!
DatLibrarian
Extends EventEmitter
Instantiate a new DatLibriarian.
Parameters
options
Object Options object.
load
Load Dat archives into cache by checking the working directory for existing archives.
Examples
librarian
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
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
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
Returns Promise A promise that resolves once the archive has been removed.
list
Lists the keys in the cache.
Examples
let keys = librarianconsole> '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> '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
Returns Promise Promise that resolves once all archives have closed.
resolve
Promification of dat-link-resolve for convenience's sake.
Parameters
Examples
DatLibrarian
Returns Promise<Buffer> Key of that Dat archive
join
Event emitted once an archive has completed its first round of peer discovery.
Examples
librarian
add
Event emitted when an archive is added.
Examples
librarian
remove
Event emitted once an archive has been removed.
Examples
librarian
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.