Skip to content

Commit

Permalink
Fixed a deprecation issue where "Buffer.from(string[, encoding])" is …
Browse files Browse the repository at this point in the history
…not supported in Node.js v5.9 and earlier versions
  • Loading branch information
cheton committed Feb 1, 2018
1 parent 7c1210a commit 1a089a6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ const flush = (parser, customFlush) => {
text = eol.lf(text);
}

let contents = null;

try {
// "Buffer.from(string[, encoding])" is added in Node.js v5.10.0
contents = Buffer.from(text);
} catch (e) {
// Fallback to "new Buffer(string[, encoding])" which is deprecated since Node.js v6.0.0
contents = new Buffer(text)
}

this.push(new VirtualFile({
path: resPath,
contents: (typeof Buffer.from === 'function')
? Buffer.from(text)
: new Buffer(text) // new Buffer() is deprecated since Node.js v5
contents: contents
}));
});
});
Expand Down

0 comments on commit 1a089a6

Please sign in to comment.