nodejs-grunt-legacy-util/0001-Fix-Buffer-warnings-by-switching-to-Buffer.from.patch
2020-12-03 15:41:14 +08:00

65 lines
2.1 KiB
Diff

From 6be9fdb20b77842151aa52d49e9dab183345b4b1 Mon Sep 17 00:00:00 2001
From: lei_ju <lj3074194431@163.com>
Date: Thu, 3 Dec 2020 15:34:48 +0800
Subject: [PATCH] Fix Buffer warnings by switching to Buffer.from
diff --git a/index.js b/index.js
index a61d9cc..7f389e6 100644
--- a/index.js
+++ b/index.js
@@ -182,16 +182,16 @@ util.spawn = function(opts, done) {
}
var child = spawn(cmd, args, opts.opts);
- var stdout = new Buffer('');
- var stderr = new Buffer('');
+ var stdout = Buffer.from('');
+ var stderr = Buffer.from('');
if (child.stdout) {
child.stdout.on('data', function(buf) {
- stdout = Buffer.concat([stdout, new Buffer(buf)]);
+ stdout = Buffer.concat([stdout, Buffer.from(buf)]);
});
}
if (child.stderr) {
child.stderr.on('data', function(buf) {
- stderr = Buffer.concat([stderr, new Buffer(buf)]);
+ stderr = Buffer.concat([stderr, Buffer.from(buf)]);
});
}
child.on('close', function(code) {
diff --git a/test/fixtures/spawn-multibyte.js b/test/fixtures/spawn-multibyte.js
index 8277711..b592341 100644
--- a/test/fixtures/spawn-multibyte.js
+++ b/test/fixtures/spawn-multibyte.js
@@ -4,7 +4,7 @@
// A multibyte buffer containing all our output. We will slice it later.
// In this case we are using a Japanese word for hello / good day, where each
// character takes three bytes.
-var fullOutput = new Buffer('こんにちは');
+var fullOutput = Buffer.from('こんにちは');
// Output one full character and one third of a character
process.stdout.write(fullOutput.slice(0, 4));
diff --git a/test/index.js b/test/index.js
index 4a657be..55cf79f 100644
--- a/test/index.js
+++ b/test/index.js
@@ -477,10 +477,10 @@ exports['util.recurse'] = {
'buffer': function(test) {
test.expect(1);
var actual = util.recurse({
- buf: new Buffer('buf'),
+ buf: Buffer.from('buf'),
}, this.typeValue);
var expected = {
- buf: {type: 'buffer', value: new Buffer('buf')},
+ buf: {type: 'buffer', value: Buffer.from('buf')},
};
test.deepEqual(actual, expected, 'Should not mangle Buffer instances.');
test.done();
--
2.23.0