Code Monkey home page Code Monkey logo

hyperdrive-ln's Introduction

hyperdrive-ln

NPM Version JavaScript Style Guide

create symbolic link between hyperdrives

npm i hyperdrive-ln

Usage

const ln = require('hyperdrive-ln')

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

ln.link(archive, 'linkfile', <ARCHIVE KEY>, [meta], err => {}) // create symlink to another archive
ln.readlink(archive, 'linkfile', (err, link) => {}) // get link data

// assume ln.link(archive, 'path/to/file', <ARCHIVE KEY>)
ln.resolve(archive, 'path/to/file/within/linked/archive', (err, link, restOfThePath)) // returns (err, {link: <ARCHIVE_KEY>, 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:

ln.link(archive, 'foo/bar', '<LINK_KEY>', (err) => {
    ln.resolve(archive, 'foo/bar/baz', (err, link, path) => {
      // link === {link: '<LINK_KEY>', 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.

callback cb(err, result) where result is a recursive structure:

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

ln.deepResolve(drive, swarmer, archive1, '/foo/bar/baz/baz.txt', cb)

will get the result:

{
  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

hyperdrive-ln's People

Contributors

poga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mdheller

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.