如何使用 bash 脚本修复 onedrive 损坏的 zip

Fre*_*edo 6 zip shell-script binary

目前 onedrive 生成​​的 zip 文件已被大多数软件破坏。

https://www.bitsgalore.org/2020/03/11/does-microsoft-onedrive-export-large-ZIP-files-that-are-corrupt

正如我们在这里看到的,解决方案是使用十六进制编辑器。由于我有很多大文件,我想要 bash 脚本解决方案……这可能吗?

这是一个免费提供的测试文件:

https://zenodo.org/record/3715394

pmq*_*mqs 8

问题中的链接中提到的问题,Microsoft OneDrive 是否导出损坏的大型 ZIP 文件?, 指的是 OneDrive 创建的大于 4Gig 的文件有无效的问题Total Number of Disks字段的问题End Central Directory Locator。此字段中的值应为 1,但 OneDrive(似乎是 Windows 发送到 zip)将其设置为 0。这使得使用标准解压缩实用程序处理这些文件变得困难/不可能。

unzip对这些文件之一运行会产生这样的输出

$ unzip -l  onedrive-zip-test-zeros.zip
Archive:  onedrive-zip-test-zeros.zip
warning [onedrive-zip-test-zeros.zip]:  1073742329 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [onedrive-zip-test-zeros.zip]:  start of central directory not found;
  zipfile corrupt.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)
Run Code Online (Sandbox Code Playgroud)

原始问题中的链接显示了如何使用十六进制文件编辑器手动修复问题。或者,请参阅Fix-OneDrive-Zip以获取将修复这些 OneDrive zip 文件的脚本。如果它被错误地设置为 0,它所做的就是将值设置为 1。

用法是

fix-onedrive-zip file1.zip 
Run Code Online (Sandbox Code Playgroud)

在这种情况下

$./fix-onedrive-zip onedrive-zip-test-zeros.zip 

Checking 'onedrive-zip-test-zeros.zip'
Updated 'onedrive-zip-test-zeros.zip'
Run Code Online (Sandbox Code Playgroud)

并检查可以读取 zip 文件

$ unzip -l onedrive-zip-test-zeros.zip 
Archive:  onedrive-zip-test-zeros.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
1073741824  2020-03-18 14:48   onedrive-zip-test-zeros/file01.dat
1073741824  2020-03-18 14:51   onedrive-zip-test-zeros/file02.dat
1073741824  2020-03-18 14:54   onedrive-zip-test-zeros/file03.dat
1073741824  2020-03-18 14:57   onedrive-zip-test-zeros/file04.dat
1073741824  2020-03-18 15:01   onedrive-zip-test-zeros/file05.dat
---------                     -------
5368709120                     5 files
Run Code Online (Sandbox Code Playgroud)