-
-
Save oliverturner/f2a3caec09bef093d952d9610ad76104 to your computer and use it in GitHub Desktop.
This file contains hidden or 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