Created
February 2, 2018 14:30
-
-
Save mafintosh/5ac016310c1b183433a382fed1e5ff56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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