node.js - Gulp/Node: file content stream filter with isStream=true -


i haven't found example online on how handle isstream mode manually. find prefixing/appending text , letting through() handle actual streaming:

if (file.isstream()) {     var stream = through();     stream.write(prefixtext);     file.contents = file.contents.pipe(streamer); } 

i want filter file content through encodeuri(), though. how do that?

you want like:

if (file.isstream()) {   var     encoding = 'utf8',     contents = [];    function write (chunk, enc, done) {     contents.push(chunk);     done();   }    function end (done) {     // concat stored buffers , convert string.     contents = buffer.concat(contents).tostring(encoding);     // encodeuri() string.     contents = encodeuri(contents);     // make new buffer output of encodeuri().     contents = buffer(contents, encoding);     // push new buffer.                     this.push(contents);     done();   }    // assumes want file.contents stream in end.   file.contents = file.contents.pipe(through(write, end)); } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -