我有一個node.js緩衝區實例,其中緩衝區是連接的部分,每個部分都有一個20字節的頭部,然後是放縮的數據。如何確定從傳遞給node.js zlib.inflate的緩衝區中讀取的字節數?
我需要的是使用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);
});
我不認爲數據暴露在任何地方。 Zip期望'buffer'包含所有的數據,所以它沒有用戶知道停止的地方的概念。爲什麼你需要爲這一切使用一個緩衝區? – loganfsmyth
緩衝區並不重要,我需要的是解析與未壓縮數據混合的壓縮數據。爲了正確地調整位置,我需要知道壓縮序列的長度,只能通過解析它來完成。既然zlib已經做了解析,我寧願用它來獲取這些信息,而不是自己重新實現它。 –