# hyperdrive-prefix

> prefix a hyperdrive archive with a path

Latest version **1.3.0** (published 2016-07-21) · BSD license · 0 weekly downloads

## Install

```sh
npm install hyperdrive-prefix
pnpm add hyperdrive-prefix
yarn add hyperdrive-prefix
bun add hyperdrive-prefix
```

## 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 | 1.3.0 |
| Published | 2016-07-21 |
| First published | 2016-05-12 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | substack |
| Maintainers | substack |
| Keywords | hyperdrive, directory, subdirectory |

## Links

- npm: https://www.npmjs.com/package/hyperdrive-prefix
- Repository: https://github.com/substack/hyperdrive-prefix
- Homepage: https://github.com/substack/hyperdrive-prefix#readme
- Issues: https://github.com/substack/hyperdrive-prefix/issues
- npm.io page: https://npm.io/package/hyperdrive-prefix

## Dependencies (6)

- [once](https://npm.io/package/once.md) ^1.3.3
- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [through2](https://npm.io/package/through2.md) ^2.0.1
- [duplexify](https://npm.io/package/duplexify.md) ^3.4.3
- [quotemeta](https://npm.io/package/quotemeta.md) ~0.0.0
- [collect-stream](https://npm.io/package/collect-stream.md) ^1.1.1

## Recent versions

- 1.3.0 (latest) — 2016-07-21
- 1.2.2 — 2016-07-03
- 1.2.1 — 2016-05-19
- 1.2.0 — 2016-05-19
- 1.1.0 — 2016-05-12
- 1.0.1 — 2016-05-12
- 1.0.0 — 2016-05-12

## README

# hyperdrive-prefix

prefix a hyperdrive archive with a path

# example

``` js
var hyperdrive = require('hyperdrive')
var memdb = require('memdb')
var collect = require('collect-stream')
var prefix = require('../')

var drive = hyperdrive(memdb())
var archive = drive.createArchive()

var dir1 = prefix('dir1', archive)
dir1.createFileWriteStream('hello.txt').end('BEEP BOOP\n')
dir1.createFileWriteStream('whatever.txt').end('hey\n')

var dir2 = prefix('dir2', archive)
dir2.createFileWriteStream('hello.txt').end('EHLO WORLD\n')

archive.finalize(function () {
  collect(dir1.list(), function (err, files) {
    show('DIR1/', files)
  })
  collect(dir2.list(), function (err, files) {
    show('DIR2/', files)
  })
  collect(archive.list(), function (err, files) {
    show('LIST', files)
  })
  function show (msg, files) {
    console.log(msg)
    files.forEach(function (file) { console.log('  ' + file.name) })
  }
})
```

prints:

```
LIST
  dir1/hello.txt
  dir1/whatever.txt
  dir2/hello.txt
DIR1/
  hello.txt
  whatever.txt
DIR2/
  hello.txt
```

# api

```
var prefix = require('hyperdrive-prefix')
```

## var subarchive = prefix(str)
## var subarchive = prefix(str, archive)

Create a `subarchive` of `archive` where paths are transparently prefixed with a
string `str` for writing and the prefix is transparently removed when listing
files.

The `subarchive` has many of the same methods as `archive` except for
`subarchive.finalize()` which you should perform on the `archive` instance
directly.

* `subarchive.append(entry, cb)`
* `subarchive.get(index, cb)`
* `subarchive.download(index, cb)`
* `subarchive.list()`
* `subarchive.createFileReadStream(entry)`
* `subarchive.createFileWriteStream(entry)`

`archive` is optional. You can set it later with
`subarchive.setArchive(archive)`.

## subarchive.setArchive(archive)

Set the underlying `archive` if one wasn't set up initially.

# install

```
npm install hyperdrive-prefix
```

# license

BSD

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