Skip to content

Commit

Permalink
fix: make sure Buffer.alloc exit on node < 4.5.0 (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Sep 5, 2017
1 parent 9e6f5fa commit 54abccb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ node_js:
- '8'
- '6'
- '4'
- '4.4.7'
- '4.2.3'
before_script:
- echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
script:
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm cache clean --force
- npm i --no-cache

# Post-install test scripts.
Expand Down
12 changes: 12 additions & 0 deletions lib/patch_buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

// make sure buffer.alloc exists on 4.2.3 <= Node.js < 4.5.0
// it use on tar@^4.0.0

if (typeof Buffer.alloc === 'undefined') {
Buffer.alloc = function alloc(size, fill, encoding) {
const buf = new Buffer(size);
buf.fill(fill, encoding);
return buf;
};
}
3 changes: 3 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const debug = require('debug')('npminstall:utils');
const fs = require('mz/fs');
const path = require('path');
const cp = require('child_process');

require('./patch_buffer');
const tar = require('tar');

const zlib = require('zlib');
const _rimraf = require('rimraf');
const _mkdirp = require('mkdirp');
Expand Down

0 comments on commit 54abccb

Please sign in to comment.