Automatic compression of packet header in writeRaw

This commit is contained in:
roblabla 2015-03-03 02:01:04 +00:00
parent c45c4d3cf4
commit a2b06f70a2

View File

@ -211,21 +211,18 @@ Client.prototype.write = function(packetId, params) {
// TODO : Perhaps this should only accept buffers without length, so we can // TODO : Perhaps this should only accept buffers without length, so we can
// handle compression ourself ? Needs to ask peopl who actually use this feature // handle compression ourself ? Needs to ask peopl who actually use this feature
// like @deathcap // like @deathcap
Client.prototype.writeRaw = function(buffer, shouldEncrypt) { Client.prototype.writeRaw = function(buffer) {
if (shouldEncrypt === null) { var self = this;
shouldEncrypt = true;
}
var that = this;
var finishWriting = function(buffer) { var finishWriting = function(buffer) {
var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer; var out = self.encryptionEnabled ? new Buffer(self.cipher.update(buffer), 'binary') : buffer;
that.socket.write(out); that.socket.write(out);
}; };
if (this.compressionThreshold >= 0 && buffer.length >= this.compressionThreshold) {
if(this.compressionThreshold != -1 && buffer.length > this.compressionThreshold) {
compressPacketBuffer(buffer, finishWriting); compressPacketBuffer(buffer, finishWriting);
} else if (this.compressionThreshold >= -1) {
newStylePacket(buffer, finishWriting);
} else { } else {
finishWriting(buffer); oldStylePacket(buffer, finishWriting);
} }
}; };