amazon-s3 - yauzl 返回错误:未找到中央目录记录签名的结尾
问题描述
以下 Node JS 代码总是失败:
错误:未找到中央目录记录签名的结尾
我尝试了几种 zip 文件。
// Retrieve the snapshot, which will be a zip file
S3.getObject({ Bucket: bucket, Key: snapshotPath}, (err, response) => {
console.log(`Snapshot length: ${response.Body.length}`); // confirmed the length is the same as the test file
if (err) {
throw(err);
} else {
fs.writeFileSync('/tmp/test.gz', response.Body); // (debug) confirmed this writes out a zipped file identical to the original
yauzl.fromBuffer(response.Body, {lazyEntries: true}, function(err, zipFile) {
if (err) {
console.log(`ERROR getting zipFile: ${err}`);
throw err;
}
// never makes it to here
// this will recurse through the gz file
// in our case we will have only one file, but it will be very large
zipFile.readEntry();
zipFile.on('entry', function(entry) {
...
测试文件被这样模拟:
aws.mock('S3', 'getObject', (params, callback) => {
if (params.Key.includes('Metadata')) {
...
});
} else {
console.log(`Mocking snapshot...`)
callback(null, {
AcceptRanges: "bytes",
LastModified: "Fri, 19 Jun 2020 16:38:33 GMT",
ContentLength: 940,
ETag: "\"85ca928a4d8766c8bd53607c6782db0f\"",
ContentType: "binary/octet-stream",
Metadata: {},
Body: Buffer.from(fs.readFileSync(__dirname + '/sample-data/sb2'))
});
}
我在 readFileSync 上尝试了不同的编码。yauzl 打开的文件长度为 940,与测试 zip 文件的大小一致。在压缩之前写出文件会创建一个不可压缩的文件。我尝试在 mac 上使用 gzip 文件,还尝试在 linux 上使用 gzip 创建的 zip 文件。
感谢你的协助!
解决方案
yauzl 不处理 gzip 或 gunzip。见https://github.com/thejoshwolfe/yauzl/issues/104
推荐阅读
- android - Firebase 操作似乎正在自行清除我的 EditText
- junit5 - JUnit 5 扩展的配置
- git - 具有 80% 相似度的两种类型产品的 Git 工作流程
- php - 如何在使用 laravel 5.4 将电话号码存储在控制器变量中之前跳过 0041 和 0
- c# - 如何实例化 Prism 中的所有视图
- verilog - 使端口向量中的一些位断开连接。Verilog 模块实例化
- java - 使 @Transactional 和 @Rollback 与 Spring Boot Test 一起工作
- java - 类加载器加载不正确的 log4j.xml
- c# - 从文本中获取一行的一部分作为字符串
- ios - 使用详细视图中的按钮浏览masterTableView,但当值大于/小于intableview的行数时按钮消失