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
// handle compression ourself ? Needs to ask peopl who actually use this feature
// like @deathcap
Client.prototype.writeRaw = function(buffer, shouldEncrypt) {
if (shouldEncrypt === null) {
shouldEncrypt = true;
}
var that = this;
Client.prototype.writeRaw = function(buffer) {
var self = this;
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);
};
if(this.compressionThreshold != -1 && buffer.length > this.compressionThreshold) {
if (this.compressionThreshold >= 0 && buffer.length >= this.compressionThreshold) {
compressPacketBuffer(buffer, finishWriting);
} else if (this.compressionThreshold >= -1) {
newStylePacket(buffer, finishWriting);
} else {
finishWriting(buffer);
oldStylePacket(buffer, finishWriting);
}
};