Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c499f76

Browse files
committed
[Fix] Buffer.from and Buffer.alloc require node 4+
Introduced by #419
1 parent 3fc1a9b commit c499f76

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/form_data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var fs = require('fs');
88
var mime = require('mime-types');
99
var asynckit = require('asynckit');
1010
var populate = require('./populate.js');
11+
var Buffer = require('safe-buffer').Buffer; // eslint-disable-line no-shadow
1112

1213
// Public API
1314
module.exports = FormData;
@@ -314,7 +315,7 @@ FormData.prototype.getBoundary = function() {
314315
};
315316

316317
FormData.prototype.getBuffer = function() {
317-
var dataBuffer = new Buffer.alloc( 0 );
318+
var dataBuffer = new Buffer.alloc(0);
318319
var boundary = this.getBoundary();
319320

320321
// Create the form content. Add Line breaks to the end of data.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"dependencies": {
4444
"asynckit": "^0.4.0",
4545
"combined-stream": "^1.0.6",
46-
"mime-types": "^2.1.12"
46+
"mime-types": "^2.1.12",
47+
"safe-buffer": "^5.2.1"
4748
},
4849
"devDependencies": {
4950
"@types/node": "^12.0.10",

test/integration/test-get-buffer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
'use strict';
2+
3+
var Buffer = require('safe-buffer').Buffer; // eslint-disable-line no-shadow
4+
15
var common = require('../common');
26
var assert = common.assert;
37

0 commit comments

Comments
 (0)