npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multiblob-http

v1.2.1

Published

serve content-addressed blobs over http

Downloads

214

Readme

multiblob-http

serve content-addressed blobs over http. see use with multiblob

example

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 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