I have a node.js Buffer instance, where the buffer is a concatenation of sections, and each section has a 20 byte header followed by deflated data.
What I need is to read the deflated data using node.js, and know how many bytes the deflated sequence had so I can properly advance to the next buffer section. Something like this:
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);
});