为什么我上传的GZIP文件可以使用zlib.gunzip()
解压缩,但上传的ZIP文件导致[Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR'
出现zlib.inflate()
错误,使用以下代码?
if (req.body.compression == 'GZIP') {
zlib.gunzip(body, function(err, dezipped) {
if (typeof dezipped != 'undefined') {
var xmlData = dezipped.toString('utf-8');
app.parseAndOffload(req, res, xmlData);
} else
res.status(400).send('Could not decompress as GZIP file')
});
//-> Decompresses perfectly
} else
if (req.body.compression == 'ZIP') {
zlib.inflate(body, function(err, dezipped) {
if (typeof dezipped != 'undefined') {
var xmlData = dezipped.toString('utf-8');
app.parseAndOffload(req, res, xmlData);
} else
res.status(400).send('Could not decompress as ZIP file')
});
//-> [Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR'
}