JS: Switch from `new Buffer` to `Buffer.from`

Summary:
Constructing `Buffer` using the constructor [[https://nodesource.com/blog/understanding-the-buffer-deprecation-in-node-js-10/ | has been deprecated in Node 10 due to security considerations]].

This is a simple and straightforward conversion.

Reviewed By: mjesun

Differential Revision: D13080655

fbshipit-source-id: 100d8f28c3b255422b26e820aaadcc4f32f41e0d
This commit is contained in:
Tim Yung 2018-11-15 10:41:52 -08:00 коммит произвёл Facebook Github Bot
Родитель 5939d078a0
Коммит d9c2cdae41
3 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -35,7 +35,7 @@ server.on('connection', ws => {
console.log('Received message:', message);
console.log('Cookie:', ws.upgradeReq.headers.cookie);
if (respondWithBinary) {
message = new Buffer(message);
message = Buffer.from(message);
}
if (message === 'getImage') {
message = fs.readFileSync(path.resolve(__dirname, 'flux@3x.png'));

Просмотреть файл

@ -43,7 +43,7 @@ function create() {
process.stdin.setRawMode(true);
}
var buf = new Buffer(3);
var buf = Buffer.from(3);
var str = '',
character,
read;
@ -62,7 +62,7 @@ function create() {
insert = str.length;
process.stdout.write('\u001b[2K\u001b[0G' + ask + str);
process.stdout.write('\u001b[' + (insert + ask.length + 1) + 'G');
buf = new Buffer(3);
buf = Buffer.from(3);
}
continue; // any other 3 character sequence is ignored
}

Просмотреть файл

@ -23,15 +23,15 @@ function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin':
var child = spawn('pbcopy', []);
child.stdin.end(new Buffer(content, 'utf8'));
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
case 'win32':
var child = spawn('clip', []);
child.stdin.end(new Buffer(content, 'utf8'));
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
case 'linux':
var child = spawn(xsel, ['--clipboard', '--input']);
child.stdin.end(new Buffer(content, 'utf8'));
child.stdin.end(Buffer.from(content, 'utf8'));
return true;
default:
return false;