Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Created February 2, 2018 14:30
Show Gist options
  • Save mafintosh/5ac016310c1b183433a382fed1e5ff56 to your computer and use it in GitHub Desktop.
Save mafintosh/5ac016310c1b183433a382fed1e5ff56 to your computer and use it in GitHub Desktop.
const stream = require('stream')
const cache = new Map() // you might wanna use an lru here
function createCacheStream (url) {
const buf = []
return stream.Transform({
transform: function (data, enc, cb) {
buffer.push(data)
cb(null, data)
},
flush: function (cb) {
cache.set(url, Buffer.concat(buf))
cb()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment