我有一个 node.js 缓冲区实例,其中缓冲区是节的串联,每个节都有一个 20 字节的标头,后跟放气的数据。
我需要的是使用 node.js 读取压缩数据,并知道压缩序列有多少字节,这样我就可以正确地前进到下一个缓冲区部分。像这样的东西:
var zlib = require('zlib');
var sections = [];
// A variable named 'buffer' is declared pointing to the Buffer instance
// so I need to read the first section, then the second section etc.
buffer = buffer.slice(20); // skip the 20-byte header
zlib.inflate(buffer, function(err, inflatedData) {
sections.push(inflatedData);
});
// How many bytes zlib readed from the buffer to
// create the 'inflatedData' instance?
// suppose the number of bytes read is pointed by the variable 'offset',
// then I could do this to read the next section:
buffer = buffer.slice(offset + 20);
zlib.inflate(buffer, function(err, inflatedData) {
sections.push(inflatedData);
});