Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created May 20, 2014 09:23
Show Gist options
  • Save nbqx/7828a30c82d9293a0cb9 to your computer and use it in GitHub Desktop.
Save nbqx/7828a30c82d9293a0cb9 to your computer and use it in GitHub Desktop.
var thr = require('through2');
module.exports = function(v){
return thr(function(c,e,n){
this.push(v(c));
n();
});
};
if(!module.parent){
var fs = require('fs');
var forJpg = function(buf){
for(var i=0; i<buf.length; i++){
if(buf[i]===18){
if(Math.random()>0.5){
buf[i] = Math.floor(Math.random()*10);
}else{
buf[i] = buf[i+1];
}
}
}
return new Buffer(buf)
};
fs.createReadStream('test.jpg')
.pipe(module.exports(forJpg))
.pipe(fs.createWriteStream('out.jpg'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment