Created
May 20, 2014 09:23
-
-
Save nbqx/7828a30c82d9293a0cb9 to your computer and use it in GitHub Desktop.
This file contains 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
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