hyperdrive
Advanced tools
Comparing version 3.5.1 to 4.0.0
@@ -13,3 +13,2 @@ var constants = require('constants') | ||
var pumpify = require('pumpify') | ||
var octal = require('octal') | ||
var util = require('util') | ||
@@ -25,5 +24,2 @@ var events = require('events') | ||
var DMODE = octal(755) | ||
var FMODE = octal(644) | ||
module.exports = Hyperdrive | ||
@@ -386,4 +382,2 @@ | ||
if (!entry.name) throw new Error('entry.name is required') | ||
if (!entry.type && entry.mode) entry.type = modeToType(entry.mode) | ||
if (entry.type && !entry.mode) entry.mode = entry.type === 'directory' ? DMODE : FMODE | ||
if (!opts) opts = {} | ||
@@ -477,4 +471,4 @@ | ||
var ws = self.append({ | ||
type: modeToType(st.mode), | ||
name: name, | ||
mode: st.mode, | ||
size: 0, | ||
@@ -481,0 +475,0 @@ link: null |
{ | ||
"name": "hyperdrive", | ||
"version": "3.5.1", | ||
"version": "4.0.0", | ||
"description": "A file sharing network based on rabin file chunking and append only feeds of data verified by merkle trees.", | ||
@@ -22,3 +22,2 @@ "main": "index.js", | ||
"mkdirp": "^0.5.1", | ||
"octal": "^1.0.0", | ||
"protocol-buffers": "^3.1.4", | ||
@@ -25,0 +24,0 @@ "pump": "^1.0.1", |
@@ -39,22 +39,15 @@ # hyperdrive | ||
``` js | ||
var disc = require('discovery-channel')() | ||
var swarm = require('discovery-swarm')() | ||
var hyperdrive = require('hyperdrive') | ||
var net = require('net') | ||
var level = require('level') | ||
var db = levelup('./another-hyperdrive.db') | ||
var db = level('./another-hyperdrive.db') | ||
var drive = hyperdrive(db) | ||
var link = new Buffer({your-hyperdrive-link-from-the-above-example}, 'hex') | ||
var link = new Buffer('your-hyperdrive-link-from-the-above-example', 'hex') | ||
var server = net.createServer(function (socket) { | ||
socket.pipe(drive.createPeerStream()).pipe(socket) | ||
swarm.listen() | ||
swarm.join(link) | ||
swarm.on('connection', function (connection) { | ||
connection.pipe(drive.createPeerStream()).pipe(connection) | ||
}) | ||
server.listen(0, function () { | ||
disc.add(link, server.address().port) | ||
disc.on('peer', function (hash, peer) { | ||
var socket = net.connect(peer.port, peer.host) | ||
socket.pipe(drive.createPeerStream()).pipe(socket) | ||
}) | ||
}) | ||
``` | ||
@@ -116,6 +109,8 @@ | ||
#### `archive.appendFile(filename, [name], [callback])` | ||
#### `var progress = archive.appendFile(filename, [name], [callback])` | ||
Append a file to a non-finalized archive. If you don't specify `name` the entry will be called `filename`. | ||
Returns a [progress](#progress-stats-and-events) object. | ||
#### `archive.finalize([callback])` | ||
@@ -146,3 +141,3 @@ | ||
#### `archive.download(index, [callback])` | ||
#### `var progress = archive.download(index, [callback])` | ||
@@ -152,2 +147,11 @@ Downloads the file specified by index and calls the callback when done. | ||
Returns a [progress](#progress-stats-and-events) object. | ||
#### `archive.lookup(name, callback)` | ||
Get metadata for file specified by name and calls `callback` when done. | ||
Callback will return entry as second argument. If no file is found `callback` will be called without a second argument. | ||
You can use the entry to download the file: `archive.download(entry)`. | ||
#### `var rs = archive.createFileStream(index)` | ||
@@ -161,4 +165,24 @@ | ||
#### `progress` Stats and Events | ||
A progress object is returned for `archive.download` and `archive.appendFile`. The progress object will contain stats for a single download/append: | ||
```javascript | ||
{ | ||
bytesRead: 0, // Bytes Downloaded/Append Progress | ||
bytesTotal: 0, // Total Size of File | ||
bytesInitial: 0 // Previous download progress (file was partially downloaded, then stopped) | ||
} | ||
``` | ||
##### `progress.on('ready')` | ||
Emitted when a file download/read is ready. Will emit when progress object has `bytesTotal` and `bytesInitial` set, `bytesRead` will be 0. | ||
##### `progress.on('end')` | ||
Emitted when a file download/read is done. | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15
184
5
64039
14
921
- Removedoctal@^1.0.0
- Removedoctal@1.0.0(transitive)