HTTP server for streaming hypercore blobs
npm install hypercore-blob-server
More flexible successor to serve-drive
const BlobServer = require('hypercore-blob-server')
// store should be a corestore
const server = new BlobServer(store, options)
await server.listen()
// To get a link to a blob to
const link = server.getLink(key, {
blob: blobId,
type: 'image/jpeg'
})
// supports drive lookups also
const link = server.getLink(key, {
filename: '/foo.js'
})
store
- Corestore instance
options
:
{
port // defaults to 49833,
host // defaults to '127.0.0.1',
token // server token
protocol // 'http' | 'https'
}
Listen to requests
Generates the url used to fetch data
key
- hypercore or hyperdrive key
options
:
{
host // custom host
port // custom port
protocol: 'http' | 'https',
filename | blob
}
filename
- hyperdrive filename
blob
- blob ID in the form of { blockOffset, blockLength, byteOffset, byteLength}
When downloading blobs, you can set the Range
header to download sections of data, implement pause/resume download functionality. Offsets are zero-indexed & inclusive
Range: bytes=<start>-<end>
Range: bytes=0-300
Range: bytes=2-
Let the instance know you wanna suspend so it can make relevant changes.
Let the instance know you wanna resume from suspension. Will rebind the server etc.
Apache-2.0