zkat / cacache

💩💵 but for your data. If you've got the hash, we've got the cache ™ (moved)

Home Page:https://github.com/npm/cacache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hasContent should return the file size

zkat opened this issue · comments

Since #49 landed, index entries store content size data. This data is critically important when it comes to quickly making decisions about whether to stream or do bulk operations on content.

The missing piece now is that content-addressed interactions don't have a way to figure out the size of the data they're about to process.

So, hasContent, which is usually the entry point to this, should return size information for the file if it happens to find it, along with the SRI. The change required for this is mostly pretty small: lib/content/read.js is the one with hasContent, and that function already calls out to fs.lstat. All that's left is to thread the data through (probably wrap the sri return value so you get {sri, stat}. hasContent itself, when it succeeds, should return an object that looks like {sri, size}. Otherwise, false.

Since I expect it to be a relatively small patch, I've marked this as a good starter issue. Also one that will have some seriously awesome performance impact in the libraries using it! Very soon, and very tangibly! make-fetch-happen and pacote already have places to drop this in for speeeeedz.

Could I have a take on this? :)

All yours!