Socket
Socket
Sign inDemoInstall

hyperdrive

Package Overview
Dependencies
Maintainers
1
Versions
271
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperdrive - npm Package Compare versions

Comparing version 1.4.2 to 1.4.3

SPECIFICATION.md

25

example.js

@@ -7,3 +7,3 @@ var hyperdrive = require('./')

var hash = new Buffer('ee4565bb12e34cfa90af4b8806251c1ddcd2350e7edafb971ef29faaee5b293d', 'hex')
var hash = new Buffer('cb8f51acc3e21baee2307c4425fe1c302a9a2c9eb02adfa980bda3461ed2a8df', 'hex')

@@ -26,5 +26,2 @@ function run (name) {

// var a = file.cursor()
// a.read(2, console.log)
file.get(inc++, function loop (err, block) {

@@ -72,21 +69,1 @@ if (err) throw err

run(process.argv[2] || 'test')
// var remote = hyperdrive(require('memdb')(), {name: 'remote'})
// var f = remote.get('0fc4a1644ec17df7e69a35a35fe1eb7e3823b41576dc2dab783ea41357a19487')
// var s1 = drive.swarm.createStream()
// var s2 = remote.swarm.createStream()
// s1.pipe(s2).pipe(s1)
// // f.get(0, function (err, entry) {
// // console.log(entry, '<-- metadata feed')
// // var f2 = remote.get(entry.link)
// // f2.get(0, function () {
// // f2.get(4, function (err, blk) {
// // console.log('-->', blk)
// // })
// // })
// // // var nested = drive.get(entry.link)
// // })

@@ -40,7 +40,11 @@ var constants = require('constants')

var self = this
var type = file.type || 'file'
if (!file) file = {}
if (!file.mode) file.mode = file.type === 'directory' ? octal(755) | constants.S_IFDIR : octal(644)
if (!file.mode) file.mode = type === 'directory' ? octal(755) | constants.S_IFDIR : octal(644)
if (constants.S_IFDIR & file.mode) return add(null)
if (constants.S_IFDIR & file.mode) {
type = 'directory'
return add(null)
}

@@ -72,3 +76,3 @@ var content = writeStream(this.drive, {chunk: true})

var entry = {
type: 'file',
type: type,
value: messages.File.encode(file),

@@ -75,0 +79,0 @@ link: link

@@ -88,3 +88,2 @@ var protocol = require('./protocol')

function chooseBlock (peer) {

@@ -91,0 +90,0 @@ // TODO: maintain a bitfield of perswarm blocks in progress

{
"name": "hyperdrive",
"version": "1.4.2",
"version": "1.4.3",
"description": "A file sharing network based on rabin file chunking and append only feeds of data verified by merkle trees.",

@@ -5,0 +5,0 @@ "main": "index.js",

# hyperdrive
A file sharing network based on [rabin](https://github.com/maxogden/rabin) file chunking and
append only feeds of data verified by merkle trees.
A file sharing network based on [rabin](https://github.com/maxogden/rabin) file chunking and append only feeds of data verified by merkle trees.

@@ -12,6 +11,7 @@ ```

# Status
For a more detailed technical information on how it works see [SPECIFICATION.md](SPECIFICATION.md). It runs in node.js as well as in the browser. [Try a browser based demo here](http://mafintosh.github.io/hyperdrive)
## Status
## Almost ready for prime time :rocket:
## Feel free to open issues and ask questions

@@ -23,6 +23,8 @@ APIs/protocols might be still break.

- [ ] Storing downloaded files as actual files (not in leveldb doh)
- [ ] Full documention of the apis/protocols
- [x] Full documention of the apis/protocols
- [ ] Tit-for-tat swarm logic
- [ ] Integrate peer discovery (currently has be handled externally)
- [ ] Tests for internal logic
- [ ] pass in a hypercore instead of leveldb
- [x] peer discovery events so a dht would know what to look for (in hypercore)
- [x] Tests for internal logic (in hypercore)
- [x] Move archive/file abstractions to new modules (moved core out to hypercore)
- [x] A bit of refactoring

@@ -37,3 +39,5 @@

var fs = require('fs')
var levelup = require('levelup')
var aLevelDB = levelup('./my-drive')
var drive = hyperdrive(aLevelDB)

@@ -60,3 +64,10 @@

var disc = require('discovery-channel')()
var hyperdrive = require('hyperdrive')
var net = require('net');
var levelup = require('levelup')
var aLevelDB = levelup('./mydb')
var drive = hyperdrive(aLevelDB)
var link = new Buffer({your-hyperdrive-link-from-the-above-example}, 'hex')
var server = net.createServer(function (socket) {

@@ -75,3 +86,3 @@ socket.pipe(drive.createPeerStream()).pipe(socket)

var lookup = disc.lookup(hash.slice(0, 20))
var lookup = disc.lookup(link.slice(0, 20))

@@ -101,4 +112,89 @@ lookup.on('peer', function (ip, port) {

## API
## Stability: UNSTABLE, likely to have major changes
#### `var drive = hyperdrive(db)`
Create a new hyperdrive instance. db should be a [levelup](https://github.com/level/levelup) instance.
#### `var stream = drive.createPeerStream()`
Create a new peer replication duplex stream. This stream should be piped together with another
peer stream somewhere else to start replicating the feeds
#### `var archive = drive.add()`
Add a new archive to share.
#### `var stream = archive.entry(fileInfo, [cb])`
Add a new file entry to the file archive. `fileInfo` should look like this
``` js
{
name: 'dir/filename', // required
type: 'file or directory', // detected using the mode if not provided
mode: 0666, // optional
uid: 0, // optional
gid: 0, // optional
mtime: mtimeInSeconds // optional
ctime: ctimeInSeconds // optional
}
```
The stream returned is a writable stream. You should write the file contents to that.
If you are writing a directory the stream will be `null`.
Optionally you can provide a callback that is called when the content has been written
#### `archive.finalize([cb])`
Finalize the archive. After the callback has been called you can get the feed `id`
by accessing `archive.id`.
#### `var feed = drive.get(id_or_entry)`
Access a feed by it's id or entry object.
The entry object looks like this
``` js
{
type: 'metadata or file',
value: optionalValueCorrespondingToTheType,
link: {
id: feedId,
blocks: blocksInFeed
}
}
```
If you just pass in a `feedId` the type will default to `metadata`.
#### `feed.get(index, callback)`
Get a block from the the feed.
* If the feed is an metadata feed the return value will be an `entry` object.
* If the feed is a file feed it will be a buffer.
#### `var stream = feed.createStream()`
Create a readable stream of all entries in the feed.
The values will be of the same type as described in `feed.get`
#### `var cursor = feed.cursor()`
If the feed is a file feed you can create a random access cursor by calling `var cursor = feed.cursor()`.
#### `cursor.read(byteOffset, callback)`
Will return a buffer stored at that byte offset in the file.
#### `cursor.next(callback)`
Will return the next buffer at the current cursor position.
## License
MIT

@@ -5,2 +5,3 @@ var tape = require('tape')

var hyperdrive = require('../')
var dir = require('fs').statSync('.')

@@ -28,2 +29,24 @@ tape('pack', function (t) {

tape('pack with dir', function (t) {
var drive = create()
var pack = drive.add()
var stream = pack.entry({
name: 'folder',
mode: dir.mode
})
t.same(stream, null)
pack.finalize(function () {
var feed = drive.get(pack.id)
feed.get(0, function (err, entry) {
t.error(err)
t.same(entry.type, 'directory')
t.end()
})
})
})
tape('pack and get', function (t) {

@@ -30,0 +53,0 @@ var drive = create()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc