mirror of
https://github.com/billsonnn/nitro-converter.git
synced 2024-11-29 18:50:51 +01:00
optimize zlib inflate, the old code would get stuck on malformed swfs
This commit is contained in:
parent
32435a3c84
commit
7ce2438ea5
@ -335,27 +335,9 @@ function uncompress(swf, next) {
|
|||||||
return readSWFBuff(new SWFBuffer(uncompressed_buff), swf);
|
return readSWFBuff(new SWFBuffer(uncompressed_buff), swf);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBuffer = swf.slice(4);
|
zlib.inflate(compressed_buff, function(err, buf) {
|
||||||
const uncompressedLength = newBuffer.readUInt32LE();
|
readSWFBuff(new SWFBuffer(buf), swf, next);
|
||||||
const chunks = [];
|
|
||||||
|
|
||||||
let readLength = 0;
|
|
||||||
var decompressStream = zlib.createInflate()
|
|
||||||
.on('data', function (chunk) {
|
|
||||||
readLength += chunk.length;
|
|
||||||
chunks.push(chunk);
|
|
||||||
|
|
||||||
if (uncompressedLength - 8 === readLength) {
|
|
||||||
decompressStream.close();
|
|
||||||
}
|
|
||||||
//decompressStream.pause();
|
|
||||||
}).on('error', function(err) {
|
|
||||||
console.log(err);
|
|
||||||
//next(err);
|
|
||||||
}).on('close', function() {
|
|
||||||
readSWFBuff(new SWFBuffer( Buffer.concat(chunks) ), swf, next);
|
|
||||||
});
|
});
|
||||||
decompressStream.write(compressed_buff);
|
|
||||||
break;
|
break;
|
||||||
case 0x46 : // uncompressed
|
case 0x46 : // uncompressed
|
||||||
return readSWFBuff(new SWFBuffer( swf ), swf, next);
|
return readSWFBuff(new SWFBuffer( swf ), swf, next);
|
||||||
|
Loading…
Reference in New Issue
Block a user