Created
October 6, 2015 09:33
-
-
Save telekosmos/8de9e72695f00ae750f7 to your computer and use it in GitHub Desktop.
node file content stream filter
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
if (file.isStream()) { | |
var | |
encoding = 'utf8', | |
contents = []; | |
function write (chunk, enc, done) { | |
contents.push(chunk); | |
done(); | |
} | |
function end (done) { | |
// Concat stored buffers and convert to string. | |
contents = Buffer.concat(contents).toString(encoding); | |
// encodeURI() string. | |
contents = encodeURI(contents); | |
// Make new buffer with output of encodeURI(). | |
contents = Buffer(contents, encoding); | |
// Push new buffer. | |
this.push(contents); | |
done(); | |
} | |
// This assumes you want file.contents to be a stream in the end. | |
file.contents = file.contents.pipe(through(write, end)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment