# node-dat-archive

> A nodejs API for Dat which is compatible with Beaker's DatArchive API

Latest version **2.2.0** (published 2018-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-dat-archive
pnpm add node-dat-archive
yarn add node-dat-archive
bun add node-dat-archive
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2018-11-04 |
| First published | 2017-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 60 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Paul Frazee |
| Maintainers | pfraze, pfrazee |
| Keywords | dat, beaker, p2p |

## Links

- npm: https://www.npmjs.com/package/node-dat-archive
- Repository: https://github.com/beakerbrowser/node-dat-archive
- Homepage: https://github.com/beakerbrowser/node-dat-archive#readme
- Issues: https://github.com/beakerbrowser/node-dat-archive/issues
- npm.io page: https://npm.io/package/node-dat-archive

## Dependencies (7)

- [dat-dns](https://npm.io/package/dat-dns.md) ^2.0.0
- [dat-node](https://npm.io/package/dat-node.md) ^3.5.3
- [concat-stream](https://npm.io/package/concat-stream.md) ^1.6.0
- [parse-dat-url](https://npm.io/package/parse-dat-url.md) ^3.0.1
- [pauls-dat-api](https://npm.io/package/pauls-dat-api.md) ^8.0.3
- [dom-event-target](https://npm.io/package/dom-event-target.md) ^1.0.0
- [beaker-error-constants](https://npm.io/package/beaker-error-constants.md) ^1.2.0

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 2.2.0 (latest) — 2018-11-04
- 2.1.0 — 2018-10-19
- 2.0.1 — 2018-02-09
- 2.0.0 — 2017-12-31
- 1.6.1 — 2017-12-19
- 1.6.0 — 2017-12-01
- 1.5.0 — 2017-09-24
- 1.4.1 — 2017-09-08
- 1.4.0 — 2017-09-08
- 1.3.1 — 2017-09-08
- 1.3.0 — 2017-08-19
- 1.2.0 — 2017-08-08
- 1.1.0 — 2017-08-06
- 1.0.3 — 2017-08-05
- 1.0.2 — 2017-08-05
- … 2 more at https://npm.io/package/node-dat-archive/versions

## README

## 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.

```js
var DatArchive = require('node-dat-archive')

// create a new archive
var archive = await DatArchive.create({
  localPath: './my-archive-data',
  title: 'My Archive',
  description: 'A test of the node DatArchive API'
})

// load an existing archive from disk
var archive = await DatArchive.load({
  localPath: './my-archive-data'
})

// load an existing archive from the URL:
var archive = new DatArchive(datURL, {localPath: './my-archive-data'})

// using the instance
await archive.writeFile('hello.txt', 'world')
var names = await archive.readdir('/')
console.log(names) // => ['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`.

```js
var archive = await DatArchive.create({
  localPath: './my-archive-data',
  datOptions: {latest: true}
})
var archive = await DatArchive.load({
  localPath: './my-archive-data',
  datOptions: {latest: true}
})
var archive = new DatArchive(datURL, {
  localPath: './my-archive-data',
  datOptions: {latest: true}
})
```

You can also pass options through to [dat-node](https://github.com/datproject/dat-node) with `datOptions`, or pass options to its `.joinNetwork([opts])` method with `netOptions`:

```js
var archive = new DatArchive(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 the `localPath` 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` and `netOptions` to configure the [dat-node](https://github.com/datproject/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 valid `mtime` or `size`.
 - `networked:` opt is not yet supported.

### Quick API reference

Refer to the [Beaker `DatArchive` docs](https://beakerbrowser.com/docs/apis/dat.html).

```js
var archive = new DatArchive(url, {localPath:, datOptions:, netOptions:})
var archive = await DatArchive.create({localPath:, datOptions:, netOptions:, title:, description:, type:, author:, networked:})
var archive = await DatArchive.load({localPath:, datOptions:, netOptions:})
var key = await DatArchive.resolveName(url)
archive.url
await archive.configure({title:, description:, type:, author:, networked:})
var info = await archive.getInfo({timeout:})
var stat = await archive.stat(path, {timeout:})
var content = await archive.readFile(path, {encoding:, timeout:})
var names = archive.readdir(path, {recursive:, stat:, timeout:})
await archive.writeFile(path, data, encoding)
await archive.mkdir(path)
await archive.unlink(path)
await archive.rmdir(path, {recursive:})
var history = await archive.history({start:, end:, reverse:, timeout:})
await archive.download(path, {timeout:})
var emitter = archive.createFileActivityStream(pattern)
var emitter = archive.createNetworkActivityStream()

// node-only:
archive._loadPromise // promise for when the archive is ready to use
archive._close() // exit swarm, close all files
```

---
_Source: https://npm.io/package/node-dat-archive · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
