# multiblob-http

> serve content-addressed blobs over http

Latest version **1.2.1** (published 2022-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install multiblob-http
pnpm add multiblob-http
yarn add multiblob-http
bun add multiblob-http
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2022-02-28 |
| First published | 2016-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 4 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | 'Dominic Tarr' |
| Maintainers | dominictarr, staltz, arj03 |

## Links

- npm: https://www.npmjs.com/package/multiblob-http
- Repository: https://github.com/ssbc/multiblob-http
- Issues: https://github.com/ssbc/multiblob-http/issues
- npm.io page: https://npm.io/package/multiblob-http

## Dependencies (4)

- [pull-many](https://npm.io/package/pull-many.md) ^1.0.9
- [pull-stream](https://npm.io/package/pull-stream.md) ^3.6.14
- [range-parser](https://npm.io/package/range-parser.md) ^1.2.1
- [stream-to-pull-stream](https://npm.io/package/stream-to-pull-stream.md) ^1.7.3

## Recent versions

- 1.2.1 (latest) — 2022-02-28
- 1.2.0 — 2021-09-29
- 1.1.0 — 2021-09-29
- 1.0.0 — 2019-04-27
- 0.4.2 — 2018-04-11
- 0.4.1 — 2018-04-11
- 0.4.0 — 2018-04-11
- 0.3.1 — 2017-12-29
- 0.3.0 — 2017-12-12
- 0.2.1 — 2017-09-26
- 0.2.0 — 2016-07-28
- 0.0.1 — 2016-07-21
- 0.0.0 — 2016-07-02

## README

# multiblob-http

serve content-addressed blobs over http.
see use with [multiblob](https://github.com/ssbc/multiblob)

# example

``` js
var MultiBlob = require('multiblob')
var MultiBlobHttp = require('multiblob-http')
var http = require('http')

var dir = where_files_go //set this.

var blobs = MultiBlob(dir)

http.createServer(MultiBlobHttp(blobs, '/blobs')).listen(8000)
```
this will return an http handler (compatible with express middleware)
that will handle requests
 * `GET /blobs/get/{id}`
 * `POST /blobs/add` (which will respond with the hash)

you can also set a different prefix, but I use `/blobs`

## http api

### GET /get/{id}

retrive blob with hash {id}

range requests [rfc 7233](https://tools.ietf.org/html/rfc7233) are supported,
This enables better video playback in browsers. Browsers tend to refuse to loop videos otherwise and seeking in videos requires range requests. It's also great for extracting embedded thumbnails from JPEGs etc.

### POST /add

posts to add do not require to have a hash, but will respond with the hash.
(TODO: take a POST to /add/{id} and error if received content did not have that hash)

## caching && headers

`multiblobs-http` provides the correct headers to make serving content-addressed
files as efficient as possible.

First the the `etag` header is set to the hash and the expires header is set to a year in the future.
Ideally, the browser shouldn't request this resource again for a whole year.
Probably it might revalidate it when someone uses `ctrl-R` to reload the page.
When it does, it will request with `if-none-modified` set to the hash.
Since content-addressed files are _never_ modified, the server immediately responds
with 304 (not modified)

the `content-length` header is always used unless "opts.size=false".
This way, if a connection fails somehow,
or there is an error later, the browser should detect it.

Of course, it would be way better if browsers just understood content-hashes.
But, we have to play the hand we where delt, and
`multiblob-http` makes the most of the broken web we live in.


## License

MIT

---
_Source: https://npm.io/package/multiblob-http · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
