Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/poga/hyperdrive-ln
create symbolic link between hyperdrives
https://github.com/poga/hyperdrive-ln
hyperdrive symlink
Last synced: 3 months ago
JSON representation
create symbolic link between hyperdrives
- Host: GitHub
- URL: https://github.com/poga/hyperdrive-ln
- Owner: poga
- License: mit
- Created: 2016-12-14T01:50:23.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-19T23:53:25.000Z (almost 8 years ago)
- Last Synced: 2024-09-29T11:47:25.953Z (4 months ago)
- Topics: hyperdrive, symlink
- Language: JavaScript
- Size: 33.2 KB
- Stars: 13
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dat - hyperdrive-ln - create symbolic links between hyperdrive archives (Outdated / Other Related Dat Project Modules)
README
# hyperdrive-ln
[![NPM Version](https://img.shields.io/npm/v/hyperdrive-ln.svg)](https://www.npmjs.com/package/hyperfeed) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
create symbolic link between [hyperdrives](https://github.com/mafintosh/hyperdrive)
`npm i hyperdrive-ln`
## Usage
```js
const ln = require('hyperdrive-ln')var drive = hyperdrive(memdb())
var archive = drive.createArchive()ln.link(archive, 'linkfile', , [meta], err => {}) // create symlink to another archive
ln.readlink(archive, 'linkfile', (err, link) => {}) // get link data// assume ln.link(archive, 'path/to/file', )
ln.resolve(archive, 'path/to/file/within/linked/archive', (err, link, restOfThePath)) // returns (err, {link: , meta: {...}}, 'within/linked/archive')// resolve through archives
ln.deepResolve(drive, swarmer, archive, path, (err, result) => {})ln.encode(key, [meta]) // encode a key for linkfile
ln.decode(data) // decode a linkfile content to key
```## API
#### `ln.link(archive, path, archiveKey, [meta], cb)`
Create a symlink at `path` point to `archiveKey`.
You can pass a `meta` object to store it in the symlink.
#### `ln.readlink(archive, path, cb)`
Get the link data stored inside a symlink.
#### `ln.resolve(archive, path, cb)`
Resolve a path. Returns an archive and a path within that archive with `cb(err, linkedArchiveKey, pathWithinLinkedArchive)`
* If there's a symlink encountered in the path. `cb(err, link, pathWithinLinkedArchive)` will be invoked.
* If there's no symlink in the path, `cb(err, {}, path)` will be called.for example:
```js
ln.link(archive, 'foo/bar', '', (err) => {
ln.resolve(archive, 'foo/bar/baz', (err, link, path) => {
// link === {link: '', meta: {...}}
// path === 'baz'
})
})
```#### `ln.deepResolve(drive, swarmer, archive, path, cb)`
Recursively resolve a path through archives. Create swarm connection when necessary.
`swarmer` is anything let you join swarm . For example: [hyperdiscovery](https://github.com/karissa/hyperdiscovery).
callback `cb(err, result)` where `result` is a recursive structure:
```js
{
archive: // traversed archive,
path: // consumed path,
swarm: // swarm instance,
next: result // next component if there's one
}
```For example: Assume we have an `archive1` which `/foo/bar` linked to `archive2`.
```js
ln.deepResolve(drive, swarmer, archive1, '/foo/bar/baz/baz.txt', cb)
```will get the result:
```js
{
archive: archive1,
path: '/foo/bar',
swarm: // a swarm instance,
next: {
archive: archive2,
path: 'baz/baz.txt',
swarm: // another swarm instance
}
}
```
use `deepClose(result)` to close all swarm instance in the result.#### `ln.deepClose(result)`
Close all swarm instance in the result.
#### `body = ln.encode(key, [meta])`
Encode a key to symlink file body.
#### `ln.decode(body)`
Decode a symlink file body to linked archive key.
## License
The MIT License