Node DatArchive
A nodejs API for Dat which is compatible with Beaker's DatArchive API. Useful for testing and for writing apps that work in the browser and in nodejs.
var DatArchive = // create a new archivevar archive = await DatArchive // load an existing archive from diskvar archive = await DatArchive // load an existing archive from the URL:var archive = datURL localPath: './my-archive-data' // using the instanceawait archivevar names = await archiveconsole // => ['hello.txt']
By default, node-dat-archive
stores the Dat data in the localPath
folder using the SLEEP format (dat's internal structure).
If you want the folder to show the latest files (the dat cli behavior) pass latest: true
in the datOptions
.
var archive = await DatArchivevar archive = await DatArchivevar archive = datURL localPath: './my-archive-data' datOptions: latest: true
You can also pass options through to dat-node with datOptions
, or pass options to its .joinNetwork([opts])
method with netOptions
:
var archive = datURL localPath: './my-archive-data' datOptions: live: true netOptions: upload: false
This will extend node-dat-archive's defaults.
Differences from Browser API
- This module adds the
localPath
parameter. Use thelocalPath
to specify where the data for the archive should be stored. If not provided, the archive will be stored in memory. - This module also adds
datOptions
andnetOptions
to configure the dat-node usage. - This module also adds
DatArchive.load()
to read an archive from disk. - This module does yet not include
DatArchive.fork
. - This module does yet not include
DatArchive.unlink
. - This module will not include
DatArchive.selectArchive
. archive.getInfo()
does not give a validmtime
orsize
.networked:
opt is not yet supported.
Quick API reference
Refer to the Beaker DatArchive
docs.
var archive = url localPath: datOptions: netOptions:var archive = await DatArchivevar archive = await DatArchivevar key = await DatArchivearchiveurlawait archivevar info = await archivevar stat = await archivevar content = await archivevar names = archiveawait archiveawait archiveawait archiveawait archivevar history = await archivehistorystart: end: reverse: timeout:await archivevar emitter = archivevar emitter = archive // node-only:archive_loadPromise // promise for when the archive is ready to usearchive // exit swarm, close all files