Fixed Buffer deprecated warnings when using node >= v10
This commit is contained in:
@ -33,8 +33,8 @@ Object.freeze(streamPosition);
|
||||
function createJsonEventData(eventId, event, metadata, type) {
|
||||
if (!event || typeof event !== 'object') throw new TypeError("data must be an object.");
|
||||
|
||||
var eventBuf = new Buffer(JSON.stringify(event));
|
||||
var metaBuf = metadata ? new Buffer(JSON.stringify(metadata)) : null;
|
||||
var eventBuf = Buffer.from(JSON.stringify(event));
|
||||
var metaBuf = metadata ? Buffer.from(JSON.stringify(metadata)) : null;
|
||||
return new EventData(eventId, type || event.constructor.name, true, eventBuf, metaBuf);
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,14 @@ function parse(s, buf, offset) {
|
||||
var ii = 0;
|
||||
|
||||
if (buf) buf.fill(0, i, i + 16);
|
||||
buf = buf || new Buffer(16);
|
||||
buf = buf || Buffer.alloc(16);
|
||||
s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {
|
||||
if (ii < 16) { // Don't overflow!
|
||||
buf[i + ii++] = _hexToByte[oct];
|
||||
}
|
||||
});
|
||||
|
||||
var buf2 = new Buffer(buf.slice(i, i + 16));
|
||||
var buf2 = Buffer.from(buf.slice(i, i + 16));
|
||||
buf[i + 0] = buf2[3];
|
||||
buf[i + 1] = buf2[2];
|
||||
buf[i + 2] = buf2[1];
|
||||
@ -44,4 +44,4 @@ function unparse(buf, offset) {
|
||||
}
|
||||
|
||||
exports.parse = parse;
|
||||
exports.unparse = unparse;
|
||||
exports.unparse = unparse;
|
||||
|
@ -24,8 +24,8 @@ function EventData(eventId, type, isJson, data, metadata) {
|
||||
this.eventId = eventId;
|
||||
this.type = type;
|
||||
this.isJson = isJson || false;
|
||||
this.data = data || new Buffer(0);
|
||||
this.metadata = metadata || new Buffer(0);
|
||||
this.data = data || Buffer.alloc(0);
|
||||
this.metadata = metadata || Buffer.alloc(0);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ EventStoreNodeConnection.prototype.setStreamMetadataRaw = function(
|
||||
if (err) return reject(err);
|
||||
resolve(result);
|
||||
}
|
||||
var data = metadata ? new Buffer(JSON.stringify(metadata)) : null;
|
||||
var data = metadata ? Buffer.from(JSON.stringify(metadata)) : null;
|
||||
var metaevent = new EventData(uuid.v4(), systemEventTypes.StreamMetadata, true, data, null);
|
||||
self._enqueueOperation(
|
||||
new AppendToStreamOperation(self._settings.log, cb, self._settings.requireMaster,
|
||||
@ -720,4 +720,4 @@ EventStoreNodeConnection.prototype._enqueueOperation = function(operation) {
|
||||
setImmediate(tryEnqueue)
|
||||
};
|
||||
|
||||
module.exports = EventStoreNodeConnection;
|
||||
module.exports = EventStoreNodeConnection;
|
||||
|
@ -50,12 +50,12 @@ TcpPackage.fromBufferSegment = function(data) {
|
||||
|
||||
TcpPackage.prototype.asBuffer = function() {
|
||||
if ((this.flags & TcpFlags.Authenticated) !== 0) {
|
||||
var loginBytes = new Buffer(this.login);
|
||||
var loginBytes = Buffer.from(this.login);
|
||||
if (loginBytes.length > 255) throw new Error("Login serialized length should be less than 256 bytes.");
|
||||
var passwordBytes = new Buffer(this.password);
|
||||
var passwordBytes = Buffer.from(this.password);
|
||||
if (passwordBytes.length > 255) throw new Error("Password serialized length should be less than 256 bytes.");
|
||||
|
||||
var res = new Buffer(MandatorySize + 2 + loginBytes.length + passwordBytes.length + (this.data ? this.data.count : 0));
|
||||
var res = Buffer.alloc(MandatorySize + 2 + loginBytes.length + passwordBytes.length + (this.data ? this.data.count : 0));
|
||||
res[CommandOffset] = this.command;
|
||||
res[FlagsOffset] = this.flags;
|
||||
guidParse.parse(this.correlationId, res, CorrelationOffset);
|
||||
@ -69,7 +69,7 @@ TcpPackage.prototype.asBuffer = function() {
|
||||
|
||||
return res;
|
||||
} else {
|
||||
var res = new Buffer(MandatorySize + (this.data ? this.data.count : 0));
|
||||
var res = Buffer.alloc(MandatorySize + (this.data ? this.data.count : 0));
|
||||
res[CommandOffset] = this.command;
|
||||
res[FlagsOffset] = this.flags;
|
||||
guidParse.parse(this.correlationId, res, CorrelationOffset);
|
||||
@ -82,4 +82,4 @@ TcpPackage.prototype.asBufferSegment = function() {
|
||||
return createBufferSegment(this.asBuffer());
|
||||
};
|
||||
|
||||
module.exports = TcpPackage;
|
||||
module.exports = TcpPackage;
|
||||
|
@ -35,7 +35,7 @@ LengthPrefixMessageFramer.prototype._parse = function(bytes) {
|
||||
throw new Error(["Package size is out of bounds: ", this._packageLength, "(max: ", this._maxPackageSize, "."].join(''));
|
||||
}
|
||||
|
||||
this._messageBuffer = new Buffer(this._packageLength);
|
||||
this._messageBuffer = Buffer.alloc(this._packageLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -58,7 +58,7 @@ LengthPrefixMessageFramer.prototype._parse = function(bytes) {
|
||||
|
||||
LengthPrefixMessageFramer.prototype.frameData = function(data) {
|
||||
var length = data.count;
|
||||
var lengthBuffer = new Buffer(HeaderLength);
|
||||
var lengthBuffer = Buffer.alloc(HeaderLength);
|
||||
lengthBuffer.writeInt32LE(length, 0);
|
||||
return [
|
||||
createBufferSegment(lengthBuffer, 0, HeaderLength),
|
||||
@ -71,4 +71,4 @@ LengthPrefixMessageFramer.prototype.registerMessageArrivedCallback = function(ha
|
||||
};
|
||||
|
||||
|
||||
module.exports = LengthPrefixMessageFramer;
|
||||
module.exports = LengthPrefixMessageFramer;
|
||||
|
Reference in New Issue
Block a user