Skip to content

Commit

Permalink
Merge pull request #80 from thesebas/passFilenameToReplaceCallback
Browse files Browse the repository at this point in the history
Pass file object to replace callback
  • Loading branch information
lazd authored Jun 20, 2017
2 parents 824e2e8 + 99474b3 commit aeeda61
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ var Transform = require('readable-stream/transform');
var rs = require('replacestream');
var istextorbinary = require('istextorbinary');

module.exports = function(search, replacement, options) {
module.exports = function(search, replacement_, options) {
return new Transform({
objectMode: true,
transform: function(file, enc, callback) {
if (file.isNull()) {
return callback(null, file);
}


if (typeof replacement_ === 'function') {
var replacement = replacement_.bind({file:file});
}else{
var replacement = replacement_;
}

function doReplace() {
if (file.isStream()) {
file.contents = file.contents.pipe(rs(search, replacement));
Expand Down

0 comments on commit aeeda61

Please sign in to comment.