Skip to content

Commit

Permalink
Don’t transform buffers to string if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 17, 2017
1 parent 270fbe6 commit 26e493e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function buffer(vinyl, opts, callback) {
streamOut: new PassThrough(),
files: [vfile]
}), function (err, status) {
var contents;

/* Skip ignored files. */
if (err && err.message === 'No input') {
return callback(null, vinyl);
Expand All @@ -80,7 +82,16 @@ function buffer(vinyl, opts, callback) {
return callback(new PluginError(name, err || 'Unsuccessful running'));
}

vinyl.contents = new Buffer(String(vfile), 'utf-8');
contents = vfile.contents;

/* istanbul ignore else - There aren’t any unified compilers
* that output buffers, but this logic is here to keep allow them
* (and binary files) to pass through untouched. */
if (typeof contents === 'string') {
contents = new Buffer(contents, 'utf8');
}

vinyl.contents = contents;

callback(null, vinyl);
});
Expand Down

0 comments on commit 26e493e

Please sign in to comment.