Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hyperdrive-http

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperdrive-http - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

49

index.js

@@ -1,2 +0,1 @@

var crypto = require('crypto')
var pump = require('pump')

@@ -11,9 +10,8 @@ var TimeoutStream = require('through-timeout')

var singleArchive = false
function HyperdriveHttp (getArchive) {
var singleArchive = false
if (typeof (getArchive) !== 'function') {
var archive = getArchive
singleArchive = true
getArchive = function (dat, cb) {
getArchive = function (datUrl, cb) {
cb(null, archive)

@@ -23,7 +21,7 @@ }

var onrequest = function (req, res) {
var dat = parse(req.url)
if (!dat) return onerror(404, res)
getArchive(dat, function (err, archive) {
var datUrl = parse(req.url)
if (!datUrl) return onerror(404, res)
getArchive(datUrl, function (err, archive) {
if (err) return onerror(err)
archiveResponse(archive, req, res)
archiveResponse(datUrl, archive, req, res)
})

@@ -33,10 +31,20 @@ }

return onrequest
function parse (url) {
var key = url.slice(1, 65)
var filename = url.slice(66)
if (!/^[0-9a-f]{64}$/.test(key) && !singleArchive) return null
else if (singleArchive) filename = url.slice(1)
return {
key: key,
filename: filename
}
}
}
function archiveResponse (archive, req, res) {
function archiveResponse (datUrl, archive, req, res) {
if (!archive) onerror(404, res)
var dat = parse(req.url)
if (!dat.filename) {
if (!datUrl.filename) {
var src = archive.list({live: false})

@@ -54,3 +62,3 @@ var timeout = TimeoutStream({

archive.get(dat.filename, cbTimeout((err, entry) => {
archive.get(datUrl.filename, cbTimeout((err, entry) => {
if (err && err.code === 'ETIMEOUT') return onerror(404, res)

@@ -62,3 +70,3 @@ if (err || !entry || entry.type !== 'file') return onerror(404, res)

res.setHeader('Access-Ranges', 'bytes')
res.setHeader('Content-Type', mime.lookup(dat.filename))
res.setHeader('Content-Type', mime.lookup(datUrl.filename))

@@ -83,14 +91,1 @@ if (!range || range < 0) {

}
function parse (url) {
var key = url.slice(1, 65)
var filename = url.slice(66)
if (!/^[0-9a-f]{64}$/.test(key) && !singleArchive) return null
else if (singleArchive) filename = url.slice(1)
return {
key: key,
discoveryKey: crypto.createHmac('sha256', Buffer(key, 'hex')).update('hypercore').digest('hex'),
filename: filename
}
}
{
"name": "hyperdrive-http",
"version": "2.1.0",
"version": "3.0.0",
"description": "Handle Hyperdrive HTTP Requests",

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

@@ -23,3 +23,4 @@ # Hyperdrive Http

// find the archive to serve
var archive = cache.get(datInfo.discoveryKey)
var discoveryKey = crypto.createHmac('sha256', Buffer(datInfo.key, 'hex')).update('hypercore').digest('hex')
var archive = cache.get(discoveryKey)
if (!archive) {

@@ -44,5 +45,4 @@ archive = drive.createArchive(datInfo.key)

key: archive.key,
discoveryKey: archive.discoveryKey,
filename: someFile.txt,
filename: someFile.txt
}
```
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