如何修复错误 - 未找到中央目录记录签名末尾?

问题描述 投票:0回答:1

首先,我使用 ffmpeg 将视频分割成帧(在 Converter 服务器,Windows 上),然后创建一个存档,需要将其传输到另一台服务器(Generator 服务器,Linux),其中包含视频和/或图像的存档、frames 和 data.json 文件应该被解压,并且存档的内容应该被进一步使用。

为了解压缩,我使用了 extract-zip 库(基于 yauzl)并使用了 util 模块中的 promisify。

问题是,当我将图像发送到转换器进行处理时,一切都按预期进行;但是,当我发送视频时,我收到此错误 -“未找到中央目录记录签名末尾”。

在我看来,问题与异步或事件循环有关。

  • 我尝试不使用promisify,但后来遇到了以下问题 - 当我需要使用存档中的数据时,该存档尚不存在(“文件夹不存在”);
  • 尝试了更多用于解压 adamzip、unzip、decompress、node-zip 的库;
  • 我试图做出一连串的承诺;
...
const fs = require('fs-extra')
const path = require('path')
cosnt util = require('util')
const extractZip = util.promisify(require('extract-zip'))
...

...
/**
* Factory that creates a project based on the archive.
* @param {string} archive Path to the source archive
* @returns {Promise.<Project>}
*/
static async create (archive) {
  const dir = fs.mkdtempSync(path.join(this.baseDir, '/'))
  await extractZip(archive, { dir })
  const data = await fs.readJson(path.join(dir, 'data.json'))
  return new this(data, dir)
}
...

/* Tried to do this w/ chaining promises:

static async create (archive) {
  const dir = fs.mkdtempSync(path.join(this.baseDir, '/'))
  await extractZip(archive, { dir })
   .then( async () => {
    const data = await fs.readJson(path.join(dir, 'data.json'))
    return data
   })
   .then( async (data) => {
    return new this(data, dir)
   })
}

*/


javascript node.js koa
1个回答
0
投票

我解决了这个问题。事实证明,我一直在从服务器异步下载一个大档案,所以纠正这一刻,一切都按预期进行。

Wrong:
fs.writeFile(...)
Correct:
fs.writeFileSync(...)

结论:面对类似的问题 - 您应该仔细检查其中涉及的整个数据传输链和函数/调用堆栈。

© www.soinside.com 2019 - 2024. All rights reserved.