node.js zlib deflate无效的windowBits问题

时间:2016-12-10 05:28:22

标签: python node.js zlib

我正在尝试将python脚本移植到node.js,并且在zlib中遇到了deflate方法的问题。

python脚本:

def compressMessage(data):
    encode_message = data
    compressor = zlib.compressobj(-1, zlib.DEFLATED, 31, 8, zlib.Z_DEFAULT_STRATEGY)
    compressed_data = compressor.compress(encode_message)
    compressed_data += compressor.flush()
    return compressed_data

python中zlib中compressobj的定义:

zlib.compressobj([level[, method[, wbits[, memlevel[, strategy]]]]])

zlib.compressobj doc

在node.js中我试过:

var zlibBuffer = zlib.deflateSync(buffer, {
    windowBits: (zlib.Z_DEFAULT_WINDOWBITS + 16)
});

失败了:

throw new Error('Invalid windowBits: ' + opts.windowBits);

我想知道如何在node.js zlib中设置windowBits,就像我在python中一样。

任何建议都将不胜感激,谢谢:)

1 个答案:

答案 0 :(得分:0)

使用zlib.gzipSync代替zlib.deflateSync