Skip to content

Commit

Permalink
Avoid Buffer constructor on newer Node.js (#3305) (#3307)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
  • Loading branch information
Gabriel "_|Nix|_" Schulhof authored and matthew-dean committed Feb 11, 2019
1 parent b50515c commit 6155c4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/less-node/environment.js
@@ -1,6 +1,8 @@
module.exports = {
encodeBase64: function encodeBase64(str) {
return new Buffer(str).toString('base64');
// Avoid Buffer constructor on newer versions of Node.js.
var buffer = (Buffer.from ? Buffer.from(str) : (new Buffer(str)));
return buffer.toString('base64');
},
mimeLookup: function (filename) {
return require('mime').lookup(filename);
Expand Down
3 changes: 2 additions & 1 deletion test/copy-bom.js
Expand Up @@ -8,7 +8,8 @@ module.exports = function() {
fs = require('fs');

var BUF_LENGTH = 64 * 1024;
var _buff = new Buffer(BUF_LENGTH);
// Avoid Buffer constructor on newer versions of Node.js
var _buff = (Buffer.alloc ? Buffer.alloc(BUF_LENGTH) : (new Buffer(BUF_LENGTH)));

function copyFolderWithBom(src, dest) {
var stats = fs.lstatSync(src);
Expand Down

0 comments on commit 6155c4d

Please sign in to comment.