hyperdrive-http
Advanced tools
Comparing version 3.1.1 to 3.2.0
14
index.js
@@ -8,2 +8,3 @@ var pump = require('pump') | ||
var encoding = require('dat-encoding') | ||
var through = require('through2') | ||
@@ -41,2 +42,3 @@ module.exports = HyperdriveHttp | ||
op = 'changes' | ||
if (singleArchive) url = url.slice(0, -8) | ||
} | ||
@@ -62,4 +64,5 @@ | ||
if (!datUrl.filename) { | ||
var src = archive.list({live: datUrl.op === 'changes'}) | ||
if (!datUrl.filename || !archive.metadata) { | ||
var opts = {live: datUrl.op === 'changes'} | ||
var src = archive.metadata ? archive.list(opts) : archive.createReadStream(opts) | ||
var timeout = TimeoutStream({ | ||
@@ -72,3 +75,8 @@ objectMode: true, | ||
}) | ||
pump(src, timeout, ndjson.serialize(), res) | ||
res.setHeader('Content-Type', 'application/json') | ||
if (archive.metadata) return pump(src, timeout, ndjson.serialize(), res) | ||
return pump(src, timeout, through.obj(function (chunk, enc, cb) { | ||
cb(null, chunk.toString()) | ||
}), ndjson.serialize(), res) | ||
} | ||
@@ -75,0 +83,0 @@ |
{ | ||
"name": "hyperdrive-http", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Handle Hyperdrive HTTP Requests", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && echo 'Error: no test specified'" | ||
"test": "standard && tape test/*.js | tap-spec" | ||
}, | ||
@@ -22,3 +22,4 @@ "keywords": [ | ||
"range-parser": "^1.2.0", | ||
"through-timeout": "^1.0.0" | ||
"through-timeout": "^1.0.0", | ||
"through2": "^2.0.1" | ||
}, | ||
@@ -32,3 +33,12 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/joehand/hyperdrive-http" | ||
"homepage": "https://github.com/joehand/hyperdrive-http", | ||
"devDependencies": { | ||
"hyperdrive": "^7.0.0", | ||
"memdb": "^1.3.1", | ||
"random-access-file": "^1.2.0", | ||
"request": "^2.73.0", | ||
"standard": "^7.1.2", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.6.0" | ||
} | ||
} |
# Hyperdrive Http | ||
Serve a [hyperdrive](https://github.com/mafintosh/hyperdrive) archive files & metadata over HTTP. For an example of use, see [dat.haus](https://github.com/juliangruber/dat.haus). | ||
Serve a [hyperdrive](https://github.com/mafintosh/hyperdrive) archive or [hypercore](https://github.com/mafintosh/hypercore) feed over HTTP. For an example of use, see [dat.haus](https://github.com/juliangruber/dat.haus). | ||
[![Travis](https://api.travis-ci.org/joehand/hyperdrive-http.svg)](https://travis-ci.org/joehand/hyperdrive-http) | ||
## Usage | ||
@@ -14,16 +16,2 @@ | ||
### URL Format | ||
Hyperdrive-http responds to any URL with a specific format. If the URL does cannot be parsed, it will return a 404. | ||
#### Multiple archives on one site | ||
* Get metadata for archive: `http://dat.haus/dat.haus/c5dbfe5521d8dddba683544ee4b1c7f6ce1c7b23bd387bd850397e4aaf9afbd9/` | ||
* Get file from archive: `http://dat.haus/dat.haus/c5dbfe5521d8dddba683544ee4b1c7f6ce1c7b23bd387bd850397e4aaf9afbd9/filename.pdf` | ||
#### Single Archive Mode | ||
* Get metadata for archive: `http://archive-example.com/` | ||
* Get file from archive: `http://archive-example.com/filename.pdf` | ||
### Setup | ||
@@ -38,12 +26,13 @@ | ||
Hyperdrive works with either a archive lookup function or a single archive: | ||
Hyperdrive works with many archives/feeds or a single archive. | ||
#### Multiple Archives | ||
If you have multiple archives, you will need to look the archive to return using the key. | ||
Initiate with an archive lookup function: | ||
`var onrequest = hyperdriveHttp(getArchive)` | ||
or pass a single archive: | ||
`var onrequest = hyperdriveHttp(archive)` | ||
The archive lookup function may look like this: | ||
The archive lookup function would look like this: | ||
```js | ||
@@ -68,2 +57,32 @@ var getArchive = function (datInfo, cb) { | ||
#### Single Archive | ||
Hyperdrive-http works great with a single archive too. It exposes the metadata at the root path and files are available without using the key. | ||
Pass a single archive on initiation: | ||
`var onrequest = hyperdriveHttp(archive)` | ||
Now your archive metadata will be available at http://example.com/ | ||
#### Hypercore Feed(s) | ||
You can also use a hypercore feed: `hyperdriveHttp(feed)` (or using a similar getArchive function) | ||
### URL Format | ||
Hyperdrive-http responds to any URL with a specific format. If the URL does cannot be parsed, it will return a 404. | ||
#### Multiple archives on one site | ||
* Get metadata for archive: `http://dat.haus/c5dbfe5521d8dddba683544ee4b1c7f6ce1c7b23bd387bd850397e4aaf9afbd9/` | ||
* Get file from archive: `http://dat.haus/c5dbfe5521d8dddba683544ee4b1c7f6ce1c7b23bd387bd850397e4aaf9afbd9/filename.pdf` | ||
#### Single Archive Mode | ||
* Get metadata for archive: `http://archive-example.com/` | ||
* Get file from archive: `http://archive-example.com/filename.pdf` | ||
#### Hypercore Mode | ||
For hypercore feeds, the data is available with the same logic as above for a single or multiple feeds. | ||
## Example | ||
@@ -70,0 +89,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
16189
8
328
0
116
8
7
1
4
+ Addedthrough2@^2.0.1