diff --git a/lib/core/cmap/message_stream.js b/lib/core/cmap/message_stream.js index ca952fc436..89c46fdb5f 100644 --- a/lib/core/cmap/message_stream.js +++ b/lib/core/cmap/message_stream.js @@ -131,7 +131,7 @@ function processMessage(stream, message, callback) { opCode: message.readInt32LE(12) }; - const ResponseType = messageHeader.opCode === OP_MSG ? BinMsg : Response; + let ResponseType = messageHeader.opCode === OP_MSG ? BinMsg : Response; const responseOptions = stream.responseOptions; if (messageHeader.opCode !== OP_COMPRESSED) { const messageBody = message.slice(MESSAGE_HEADER_SIZE); @@ -150,6 +150,8 @@ function processMessage(stream, message, callback) { const compressorID = message[MESSAGE_HEADER_SIZE + 8]; const compressedBuffer = message.slice(MESSAGE_HEADER_SIZE + 9); + // recalculate based on wrapped opcode + ResponseType = messageHeader.opCode === OP_MSG ? BinMsg : Response; decompress(compressorID, compressedBuffer, (err, messageBody) => { if (err) { callback(err);