Hyperdrive is a secure, real-time distributed file system

Overview

Hyperdrive

Hyperdrive is a secure, real-time distributed file system

Install

npm install hyperdrive@next

Note this is the Hyperdrive 11 preview based on Hypercore 10

Usage

const Hyperdrive = require('hyperdrive')
const Corestore = require('corestore')

const corestore = new Corestore('storage')

const drive = new Hyperdrive(corestore, /* optionalKey */)

const ws = drive.createWriteStream('/blob.txt')

ws.write('Hello, ')
ws.write('world!')
ws.end()

ws.on('close', function () {
  const rs = drive.createReadStream('/blob.txt')
  rs.pipe(process.stdout) // prints Hello, world!
})

API

const drive = new Hyperdrive(corestore, [key])

Creates a new Hyperdrive instance.

corestore must be an instance of Corestore.

key should be a Hypercore public key. If you do not set this, Hyperdrive will use the core at { name: 'db' } in the passed Corestore instance.

await drive.ready()

Wait for the drive to fully open. In general, you do NOT need to wait for ready unless checking a synchronous property on drive since internals await this themselves.

const buffer = await drive.get(path)

Returns the blob at path in the drive. Internally, Hyperdrive contains a metadata index of entries that "point" to offsets in a Hyperblobs instance. Blobs themselves are accessible via drive.get(path), whereas entries are accessible via drive.entry(path). If no blob exists at path, returns null.

const stream = drive.createReadStream(path)

Returns a stream that can be used to read out the blob stored in the drive at path.

const entry = await drive.entry(path)

Returns the entry at path in the drive. An entry holds metadata about a path, currently:

{
  executable: Boolean, // whether the blob at path is an executable
  linkname: null // if entry not symlink, otherwise a string to the entry this links to
  blob: { // a Hyperblob id that can be used to fetch the blob associated with this entry
    blockOffset: Number,
    blockLength: Number,
    byteOffset: Number,
    byteLength: Number
  }
}

await drive.symlink(path, linkname)

Creates an entry in drive at path that points to the entry at linkname. Note, if a blob entry currently exists at path then drive.symlink(path, linkname) will overwrite the entry and drive.get(path) will return null, while drive.entry(path) will return the entry with symlink information.

const hyperblobs = await drive.getBlobs()

Returns the hyperblobs instance storing the blobs indexed by drive entries.

const fs = require('fs')
const Corestore = require('corestore')
const Hyperdrive = require('hyperdrive')

const drive = new Hyperdrive(new Corestore('storage'))

await drive.put(__filename, fs.readFileSync(__filename))
const bufFromGet = await drive.get(__filename)

const { value: entry } = await drive.entry(__filename)
const blobs = await drive.getBlobs()
const bufFromEntry = blobs.get(entry.blob)

console.log(Buffer.compare(bufFromGet, bufFromEntry)) // prints 0

const stream = await drive.entries([options])

Returns a read stream of entries in the drive.

options are the same as the options to Hyperbee().createReadStream(options).

await drive.put(path, blob, [options])

Sets the blob in the drive at path.

path should be a utf8 string. blob should be a Buffer.

options includes:

{
  executable: true | false // whether the blob is executable or not
}

ws = drive.createWriteStream(path, [options])

Stream a blob into the drive at path. Options include

{
  executable: true | false // whether the blob is executable or not
}

await drive.del(path)

Removes the entry at path from the drive. If a blob corresponding to the entry at path exists, it is not currently deleted.

const hypercore = drive.core

The underlying Hypercore backing the drive.

const buffer = drive.key

The public key of the Hypercore backing the drive.

const buffer = drive.discoveryKey

The hash of the public key of the Hypercore backing the drive, can be used to seed the drive using Hyperswarm.

const buffer = drive.contentKey

The public key of the Hyperblobs instance holding blobs associated with entries in the drive.

const integer = drive.version

The version (offset in the underlying Hypercore) of the drive.

const Hyperdrive = drive.checkout(version)

Checks out a read-only snapshot of a Hyperdrive at a particular version.

const fs = require('fs')
const Corestore = require('corestore')
const Hyperdrive = require('hyperdrive')

const drive = new Hyperdrive(new Corestore('storage'))

await drive.put('/fst-file.txt', fs.readFileSync('fst-file.txt'))

const version = drive.version

await drive.put('/snd-file.txt', fs.readFileSync('snd-file.txt'))

const snapshot = drive.checkout(version)

console.log(await drive.get('/snd-file.txt')) // prints Buffer
console.log(await snapshot.get('/snd-file.txt')) // prints null
console.log(Buffer.compare(await drive.get('/fst-file.txt'), await snapshot.get('/fst-file.txt'))) // prints 0

const stream = drive.diff(version, folder, [options])

Efficiently create a stream of the shallow changes to folder between version and drive.version. Each entry is sorted by key and looks like this:

{
  left: <the entry in folder at drive.version for some path>,
  right: <the entry in folder at drive.checkout(version) for some path>
}

If an entry exists in drive.version of the folder but not in version, then left is set and right will be null, and vice versa.

await drive.downloadDiff(version, folder, [options])

Downloads all the blobs in folder corresponding to entries in drive.checkout(version) that are not in drive.version. In other words, downloads all the blobs added to folder up to version of the drive.

const stream = drive.list(folder, [options])

Returns a stream of all entries in the drive at paths prefixed with folder. Options include:

{
  recursive: true | false // whether to descend into all subfolders or not
}

await drive.download(folder, [options])

Downloads the blobs corresponding to all entries in the drive at paths prefixed with folder. Options are the same as those for drive.list(folder, [options]).

const stream = drive.readdir(folder)

Returns a stream of all subpaths of entries in drive stored at paths prefixed by folder.

await drive.put('/parent/child', Buffer.from('child'))
await drive.put('/parent/sibling', Buffer.from('sibling'))
for await (const path of drive.readdir('/parent')) console.log(path) // prints "child", then prints "sibling"

await downloadRange(dbRanges, blobRanges)

Downloads the entries and blobs stored in the ranges dbRanges and blobRanges.

const batch = drive.batch()

Atomically mutate the drive, has the same interface as Hyperdrive.

await batch.flush()

Atomically commit a batch of mutations to the underlying drive.

await drive.close()

Close the drive and its underlying Hypercore backed datastructures.

Comments
  • Keeping Header unencrypted for blind seeding?

    Keeping Header unencrypted for blind seeding?

    I wonder if there are any privacy problems in leaving the header of drive.core in plain text, to help services like simple-seeder blind seed an otherwise encrypted drive using one key.

    Basically using a core.session() to add encryption after the header is already written.

    opened by Nazeh 2
  • feat: hidden opts._preready

    feat: hidden opts._preready

    Similar to hypercore's opts._preready this would enable hyperdrives managers to do custom logic before emitting ready. for example key rotation to manage access control.

    While most use cases can be hacked by extending Hyperdrive it can only be added before drive.ready() is resolved, but not before drive.on('ready') is emitted.

    opened by Nazeh 0
  • Keychain

    Keychain

    Use keypear mdoule to open Hyperdrive synchronously, and derive the encrypted key for both cores.

    I tested backward compatibility with opening remote Hyperdrives built with the current version, for both public and encrypted drives.

    opened by Nazeh 0
  • Why not compact encoding for Nodes?

    Why not compact encoding for Nodes?

    Is there a reason why you chose to encode node as JSON as opposed to using compact-encoding-struct which should give similar flexibility and only add 3 bytes overhead? Would that be a welcome PR?

    opened by Nazeh 1
  • What are the storage limits for hyperdrive?

    What are the storage limits for hyperdrive?

    This is originally posted here, but since this is the next version preview going on, thought of adding here so that this can be discussed and can possibly contribute to the design / architecture.

    • (Assuming we have enough hard-disk space) Can hyperdrive be used to store large files (say 100K+ files, each 100GB) ?

    When using a local file system, it looks like all the hyperdrive block data is stored into a single file (/data) in the storage. As such that will have problems with the OS file size limits.

    What happens when the hyperdrive content becomes large? Will the hyperdrive (or hyperspace / hypercore) continue to append the blocks to the same underlying storage data file or will it spill them into different data files?

    Where can one find more information on how the file system is organized underlying for the blobs of Hyperdrive?

    opened by KrishnaPG 2
Owner
Hypercore Protocol
A fast, scalable, and secure peer-to-peer protocol for everyone
Hypercore Protocol
Deno's first lightweight, secure distributed lock manager utilizing the Redlock algorithm

Deno-Redlock Description This is an implementation of the Redlock algorithm in Deno. It is a secure, lightweight solution to control resource access i

OSLabs Beta 223 Dec 31, 2022
A Secure Web Proxy. Which is fast, secure, and easy to use.

Socratex A Secure Web Proxy. Which is fast, secure, and easy to use. This project is under active development. Everything may change soon. Socratex ex

Leask Wong 220 Dec 15, 2022
Serve file server with single zip file as file system in Deno.

zipland Serve file server with one-single zip file in Deno. Support zip just zip32 with deflated or uncompressed serving plaintext deflate Examples Yo

Yongwook Choi 18 Nov 2, 2022
The Frontend of Escobar's Inventory Management System, Employee Management System, Ordering System, and Income & Expense System

Usage Create an App # with npx $ npx create-nextron-app my-app --example with-javascript # with yarn $ yarn create nextron-app my-app --example with-

Viver Bungag 4 Jan 2, 2023
Contains html file showcasing Earthquake related data generated in the form of VR model, ArcGIS API with real-time earthquake feed and video of simulation of earthquake generated in blender

Module-EADGI-Project-All about Earthquakes Introduction Contains html file showcasing Earthquake related data generated in the form of VR model, ArcGI

Abhishek Rawat 2 Jun 9, 2022
Simple, Fast, Secure, Flat-File CMS

Bludit Simple, Fast and Flexible CMS. Bludit is a web application to build your own website or blog in seconds, it's completely free and open source.

BLUDIT 1.1k Dec 30, 2022
A bodacious, secure, headless content management system.

A bodacious, secure, headless content management system. Cassiopeia allows you to create your blog with a customizable interface and comes with a dyna

bear 4 Jan 6, 2023
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Juan Daniel 5 Dec 15, 2022
🤖 An action that fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with them from time to time.

Discord Guardian Action ??  This action fetches the list of malicious domains on Discord in different providers and creates/updates a JSON file with t

Dalton Menezes 7 Nov 30, 2022
A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Hana Yabuki 5 Jul 10, 2022
distributed-nginx nginx k8s docker micro front-end

distributed-nginx (分布式 nginx) ?? 适用于微前端的去中心化分布式部署 nginx 服务器. 特性 支持 前端服务上线下线 自动更新微前端模块配置 完全实现了分布式去中心化 支持【微前端组】 支持 redis 协议和 multicast-dns 协议 支持 命名空间 Ge

wuyun 1 Feb 25, 2022
Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more

Apache MXNet (incubating) for Deep Learning Apache MXNet is a deep learning framework designed for both efficiency and flexibility. It allows you to m

The Apache Software Foundation 20.2k Jan 5, 2023
Non-interactive publicly verifiable distributed key generation and resharing algorithm over BLS12-381

NPVDKG-RS This repository contains a mathematical presentation and some code to demonstrate our developed non-interactive publicly verifiable distribu

NATRIX Official 8 May 19, 2022
"Lerna & Distributed Task Execution" Example

Lerna Distributed Task Execution (DTE) Example/Benchmark On how to make your CI 23 times faster with a small config change New versions of Lerna can u

Victor Savkin 9 Nov 27, 2022
The Gitcoin Passport SDK is comprised of a set of libraries distributed on npm to help developers interact with Passport data living on Ceramic.

The Gitcoin Passport SDK is comprised of a set of libraries distributed on npm to help developers interact with Passport data living on [Ceramic]

Gitcoin Core 47 Dec 6, 2022
TypeScript framework for deploying distributed indexers on Aleph VMs for Solana.

Aleph Indexer Framework v0.1 The Aleph Indexer Framework is a high-level abstraction for building multithreaded indexers on Aleph. It is designed to b

Aleph.im 11 Dec 15, 2022
A front end GUI for interacting with the Stable Horde / Stable Diffusion distributed cluster

ArtBot for Stable Diffusion See it in action: https://tinybots.net/artbot ArtBot is a front-end GUI for generating images and photos with Stable Diffu

Dave Schumaker 39 Jan 2, 2023