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
Post a Comment