Fix Node.js 10 deprecation warnings

This commit is contained in:
David Stephens 2018-04-28 13:59:07 +01:00
parent 476e8f2f0c
commit f16eb6f3e6
12 changed files with 42 additions and 41 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*.pem
# Various directories
config/config.hjson
logs/
db/
dropfiles/

View File

@ -78,7 +78,7 @@ module.exports = class ArchiveUtil {
Object.keys(Config.fileTypes).forEach(mimeType => {
const fileType = Config.fileTypes[mimeType];
if(fileType.sig) {
fileType.sig = new Buffer(fileType.sig, 'hex');
fileType.sig = Buffer.alloc(fileType.sig, 'hex');
fileType.offset = fileType.offset || 0;
// :TODO: this is broken: sig is NOT this long, it's sig.length long; offset needs to allow for -negative values as well
@ -120,7 +120,7 @@ module.exports = class ArchiveUtil {
return cb(err);
}
const buf = new Buffer(this.longestSignature);
const buf = Buffer.from(this.longestSignature);
fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => {
if(err) {
return cb(err);

View File

@ -288,7 +288,7 @@ function display(client, art, options, cb) {
}
if(!options.disableMciCache) {
artHash = xxhash.hash(new Buffer(art), 0xCAFEBABE);
artHash = xxhash.hash(Buffer.from(art), 0xCAFEBABE);
// see if we have a mciMap cached for this art
if(client.mciCache) {

View File

@ -374,7 +374,7 @@ exports.getModule = class TransferFileModule extends MenuModule {
// needed for things like sz/rz
if(external.escapeTelnet) {
const tmp = data.toString('binary').replace(/\xff{2}/g, '\xff'); // de-escape
externalProc.write(new Buffer(tmp, 'binary'));
externalProc.write(Buffer.from(tmp, 'binary'));
} else {
externalProc.write(data);
}
@ -384,7 +384,7 @@ exports.getModule = class TransferFileModule extends MenuModule {
// needed for things like sz/rz
if(external.escapeTelnet) {
const tmp = data.toString('binary').replace(/\xff/g, '\xff\xff'); // escape
this.client.term.rawWrite(new Buffer(tmp, 'binary'));
this.client.term.rawWrite(Buffer.from(tmp, 'binary'));
} else {
this.client.term.rawWrite(data);
}

View File

@ -19,7 +19,7 @@ module.exports = class FNV1a {
}
if(_.isString(data)) {
data = new Buffer(data);
data = Buffer.from(data);
}
if(!Buffer.isBuffer(data)) {
@ -38,7 +38,7 @@ module.exports = class FNV1a {
digest(encoding) {
encoding = encoding || 'binary';
let buf = new Buffer(4);
let buf = Buffer.alloc(4);
buf.writeInt32BE(this.hash & 0xffffffff, 0);
return buf.toString(encoding);
}

View File

@ -26,7 +26,7 @@ const FTN_PACKET_MESSAGE_TYPE = 2;
const FTN_PACKET_BAUD_TYPE_2_2 = 2;
// SAUCE magic header + version ("00")
const FTN_MESSAGE_SAUCE_HEADER = new Buffer('SAUCE00');
const FTN_MESSAGE_SAUCE_HEADER = Buffer.from('SAUCE00');
const FTN_MESSAGE_KLUDGE_PREFIX = '\x01';
@ -273,7 +273,7 @@ function Packet(options) {
};
this.getPacketHeaderBuffer = function(packetHeader) {
let buffer = new Buffer(FTN_PACKET_HEADER_SIZE);
let buffer = Buffer.from(FTN_PACKET_HEADER_SIZE);
buffer.writeUInt16LE(packetHeader.origNode, 0);
buffer.writeUInt16LE(packetHeader.destNode, 2);
@ -311,7 +311,7 @@ function Packet(options) {
};
this.writePacketHeader = function(packetHeader, ws) {
let buffer = new Buffer(FTN_PACKET_HEADER_SIZE);
let buffer = Buffer.from(FTN_PACKET_HEADER_SIZE);
buffer.writeUInt16LE(packetHeader.origNode, 0);
buffer.writeUInt16LE(packetHeader.destNode, 2);
@ -447,8 +447,8 @@ function Packet(options) {
// Also according to the spec, the deprecated "CHARSET" value may be used
// :TODO: Look into CHARSET more - should we bother supporting it?
// :TODO: See encodingFromHeader() for CHRS/CHARSET support @ https://github.com/Mithgol/node-fidonet-jam
const FTN_CHRS_PREFIX = new Buffer( [ 0x01, 0x43, 0x48, 0x52, 0x53, 0x3a, 0x20 ] ); // "\x01CHRS:"
const FTN_CHRS_SUFFIX = new Buffer( [ 0x0d ] );
const FTN_CHRS_PREFIX = Buffer.from( [ 0x01, 0x43, 0x48, 0x52, 0x53, 0x3a, 0x20 ] ); // "\x01CHRS:"
const FTN_CHRS_SUFFIX = Buffer.from( [ 0x0d ] );
let chrsPrefixIndex = messageBodyBuffer.indexOf(FTN_CHRS_PREFIX);
if(chrsPrefixIndex < 0) {
@ -724,7 +724,7 @@ function Packet(options) {
buf.writeUInt16LE(message.meta.FtnProperty.ftn_attr_flags, 10);
buf.writeUInt16LE(message.meta.FtnProperty.ftn_cost, 12);
const dateTimeBuffer = new Buffer(ftn.getDateTimeString(message.modTimestamp) + '\0');
const dateTimeBuffer = Buffer.from(ftn.getDateTimeString(message.modTimestamp) + '\0');
dateTimeBuffer.copy(buf, 14);
};
@ -747,7 +747,7 @@ function Packet(options) {
async.waterfall(
[
function prepareHeaderAndKludges(callback) {
const basicHeader = new Buffer(34);
const basicHeader = Buffer.from(34);
self.writeMessageHeader(message, basicHeader);
//
@ -864,7 +864,7 @@ function Packet(options) {
};
this.writeMessage = function(message, ws, options) {
let basicHeader = new Buffer(34);
let basicHeader = Buffer.from(34);
self.writeMessageHeader(message, basicHeader);
ws.write(basicHeader);
@ -1054,7 +1054,7 @@ Packet.prototype.writeTerminator = function(ws) {
// From FTS-0001.016:
// "A pseudo-message beginning with the word 0000H signifies the end of the packet."
//
ws.write(new Buffer( [ 0x00, 0x00 ] )); // final extra null term
ws.write(Buffer.from( [ 0x00, 0x00 ] )); // final extra null term
return 2;
};
@ -1074,7 +1074,7 @@ Packet.prototype.writeStream = function(ws, messages, options) {
});
if(true === options.terminatePacket) {
ws.write(new Buffer( [ 0 ] )); // final extra null term
ws.write(Buffer.from( [ 0 ] )); // final extra null term
}
};

View File

@ -46,7 +46,7 @@ exports.getQuotePrefix = getQuotePrefix;
// See list here: https://github.com/Mithgol/node-fidonet-jam
function stringToNullPaddedBuffer(s, bufLen) {
let buffer = new Buffer(bufLen).fill(0x00);
let buffer = Buffer.alloc(bufLen).fill(0x00);
let enc = iconv.encode(s, 'CP437').slice(0, bufLen);
for(let i = 0; i < enc.length; ++i) {
buffer[i] = enc[i];

View File

@ -10,10 +10,10 @@ const { Parser } = require('binary-parser');
exports.readSAUCE = readSAUCE;
const SAUCE_SIZE = 128;
const SAUCE_ID = new Buffer([0x53, 0x41, 0x55, 0x43, 0x45]); // 'SAUCE'
const SAUCE_ID = Buffer.from([0x53, 0x41, 0x55, 0x43, 0x45]); // 'SAUCE'
// :TODO read comments
//const COMNT_ID = new Buffer([0x43, 0x4f, 0x4d, 0x4e, 0x54]); // 'COMNT'
//const COMNT_ID = Buffer.from([0x43, 0x4f, 0x4d, 0x4e, 0x54]); // 'COMNT'
exports.SAUCE_SIZE = SAUCE_SIZE;
// :TODO: SAUCE should be a class

View File

@ -159,8 +159,8 @@ const NEW_ENVIRONMENT_COMMANDS = {
USERVAR : 3,
};
const IAC_BUF = new Buffer([ COMMANDS.IAC ]);
const IAC_SE_BUF = new Buffer([ COMMANDS.IAC, COMMANDS.SE ]);
const IAC_BUF = Buffer.from([ COMMANDS.IAC ]);
const IAC_SE_BUF = Buffer.from([ COMMANDS.IAC, COMMANDS.SE ]);
const COMMAND_NAMES = Object.keys(COMMANDS).reduce(function(names, name) {
names[COMMANDS[name]] = name.toLowerCase();
@ -766,7 +766,7 @@ TelnetClient.prototype.handleMiscCommand = function(evt) {
};
TelnetClient.prototype.requestTerminalType = function() {
const buf = new Buffer( [
const buf = Buffer.from( [
COMMANDS.IAC,
COMMANDS.SB,
OPTIONS.TERMINAL_TYPE,
@ -777,10 +777,10 @@ TelnetClient.prototype.requestTerminalType = function() {
};
const WANTED_ENVIRONMENT_VAR_BUFS = [
new Buffer( 'LINES' ),
new Buffer( 'COLUMNS' ),
new Buffer( 'TERM' ),
new Buffer( 'TERM_PROGRAM' )
Buffer.from( 'LINES' ),
Buffer.from( 'COLUMNS' ),
Buffer.from( 'TERM' ),
Buffer.from( 'TERM_PROGRAM' )
];
TelnetClient.prototype.requestNewEnvironment = function() {
@ -793,7 +793,7 @@ TelnetClient.prototype.requestNewEnvironment = function() {
const self = this;
const bufs = buffers();
bufs.push(new Buffer( [
bufs.push(Buffer.from( [
COMMANDS.IAC,
COMMANDS.SB,
OPTIONS.NEW_ENVIRONMENT,
@ -801,10 +801,10 @@ TelnetClient.prototype.requestNewEnvironment = function() {
));
for(let i = 0; i < WANTED_ENVIRONMENT_VAR_BUFS.length; ++i) {
bufs.push(new Buffer( [ NEW_ENVIRONMENT_COMMANDS.VAR ] ), WANTED_ENVIRONMENT_VAR_BUFS[i] );
bufs.push(Buffer.from( [ NEW_ENVIRONMENT_COMMANDS.VAR ] ), WANTED_ENVIRONMENT_VAR_BUFS[i] );
}
bufs.push(new Buffer([ NEW_ENVIRONMENT_COMMANDS.USERVAR, COMMANDS.IAC, COMMANDS.SE ]));
bufs.push(Buffer.from([ NEW_ENVIRONMENT_COMMANDS.USERVAR, COMMANDS.IAC, COMMANDS.SE ]));
self.output.write(bufs.toBuffer());
@ -836,7 +836,7 @@ Object.keys(OPTIONS).forEach(function(name) {
const code = OPTIONS[name];
Command.prototype[name.toLowerCase()] = function() {
const buf = new Buffer(3);
const buf = Buffer.alloc(3);
buf[0] = COMMANDS.IAC;
buf[1] = this.command;
buf[2] = code;

View File

@ -33,7 +33,7 @@ exports.moduleInfo = {
author : 'Andrew Pamment',
};
const IAC_DO_TERM_TYPE = new Buffer( [ 255, 253, 24 ] );
const IAC_DO_TERM_TYPE = Buffer.from( [ 255, 253, 24 ] );
class TelnetClientConnection extends EventEmitter {
constructor(client) {
@ -103,7 +103,7 @@ class TelnetClientConnection extends EventEmitter {
//
let bufs = buffers();
bufs.push(new Buffer(
bufs.push(Buffer.from(
[
255, // IAC
250, // SB
@ -113,8 +113,8 @@ class TelnetClientConnection extends EventEmitter {
));
bufs.push(
new Buffer(this.client.term.termType), // e.g. "ansi"
new Buffer( [ 255, 240 ] ) // IAC, SE
Buffer.from(this.client.term.termType), // e.g. "ansi"
Buffer.from( [ 255, 240 ] ) // IAC, SE
);
return bufs.toBuffer();

View File

@ -130,8 +130,8 @@ module.exports = class User {
//
// Use constant time comparison here for security feel-goods
//
const passDkBuf = new Buffer(passDk, 'hex');
const propsDkBuf = new Buffer(propsDk, 'hex');
const passDkBuf = Buffer.from(passDk, 'hex');
const propsDkBuf = Buffer.from(propsDk, 'hex');
if(passDkBuf.length !== propsDkBuf.length) {
return callback(Errors.AccessDenied('Invalid password'));
@ -595,7 +595,7 @@ module.exports = class User {
}
static generatePasswordDerivedKey(password, salt, cb) {
password = new Buffer(password).toString('hex');
password = Buffer.from(password).toString('hex');
crypto.pbkdf2(password, salt, User.PBKDF2.iterations, User.PBKDF2.keyLen, 'sha1', (err, dk) => {
if(err) {

View File

@ -11,17 +11,17 @@ function createNamedUUID(namespaceUuid, key) {
// https://github.com/download13/uuidv5/blob/master/uuid.js
//
if(!Buffer.isBuffer(namespaceUuid)) {
namespaceUuid = new Buffer(namespaceUuid);
namespaceUuid = Buffer.from(namespaceUuid);
}
if(!Buffer.isBuffer(key)) {
key = new Buffer(key);
key = Buffer.from(key);
}
let digest = createHash('sha1').update(
Buffer.concat( [ namespaceUuid, key ] )).digest();
let u = new Buffer(16);
let u = Buffer.alloc(16);
// bbbb - bb - bb - bb - bbbbbb
digest.copy(u, 0, 0, 4); // time_low