gpt4 book ai didi

node.js - 如何计算 zip header 中 `version made by` 的值?

转载 作者:行者123 更新时间:2023-12-04 08:35:39 27 4
gpt4 key购买 nike

我正在努力计算 正确值 version made byadm-zip .
Zip Spec在我看来不清楚如何找到二进制或整数值以将选项(例如 Option 3 Unix )设置为 central header 中的相关 2 字节.
adm-zip 中的文档 header设置根本没有帮助。
来自 zip 规范 (4.4.2) 的映射:

4.4.2.2 The current mappings are:

0 - MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
1 - Amiga 2 - OpenVMS
3 - UNIX 4 - VM/CMS

我通过设置 entry.header.made 找到了一种可能的解决方案属性(property)到 788 . (entry.header as any).made = 788;(只有通过导入由另一个 zip util 创建的 zip 才能找到此值。)
谁能解释一下如何计算这个值 788从所需的选项 3 开始?
或者如何为另一个选项计算这个值,例如 10 - Windows NTFS ?

最佳答案

简短说明:
根据specification高字节代表创建 ZIP 文件的操作系统。低字节是使用的 ZIP 规范的版本。
在您的示例中:
788 = 0x0314创建 ZIP 文件的操作系统:0x03 (高字节): UNIX

4.4.2.1 The upper byte indicates the compatibility of the fileattribute information. If the external file attributesare compatible with MS-DOS and can be read by PKZIP forDOS version 2.04g then this value will be zero. If theseattributes are not compatible, then this value willidentify the host system on which the attributes arecompatible. Software can use this information to determinethe line record format for text files etc.


ZIP 规范版本: 0x14 (低字节): 版本 2.0 0x14 / 10 = 2 (主要版本号) 0x14 % 10 = 0 (次要版本号)

4.4.2.3 The lower byte indicates the ZIP specification version(the version of this document) supported by the softwareused to encode the file. The value/10 indicates the majorversion number, and the value mod 10 is the minor versionnumber.


对于 Windows NTFS,正确的“版本由”值应该是: 0x0A14 = 2580 0x0A (高字节): Windows NTFS (Win32) 0x14 (低字节): 版本 2.0
摘自 adm-zip source :
var _verMade = 0x14,
_version = 0x0A,
_flags = 0,
_method = 0,
_time = 0,
_crc = 0,
_compressedSize = 0,
_size = 0,
_fnameLen = 0,
_extraLen = 0,

_comLen = 0,
_diskStart = 0,
_inattr = 0,
_attr = 0,
_offset = 0;

switch(process.platform){
case 'win32':
_verMade |= 0x0A00;
case 'darwin':
_verMade |= 0x1300;
default:
_verMade |= 0x0300;
}
在这里你可以看到,版本 2.0 ( 0x14 ) 来自 ZIP 规范,并且有一个简单的 OR 与创建 ZIP 文件的左移操作系统。
更新:
我写了一些简单的 JavaScript 示例函数,它们返回 verMade 的正确值。并从 verMade 返回操作系统、主要和次要版本号.
套装版本:
function zip_version_set(os, spec_major, spec_minor)
{
var ret = (parseInt(spec_major, 10) * 10) + parseInt(spec_minor, 10);

switch (os) {
case "dos":
ret |= 0x0000;
break;
case "win32":
ret |= 0x0A00;
break;
case "darwin":
ret |= 0x1300;
break;
default:
ret |= 0x0300;
}

return ret;
}
用法:
参数 os :
把她的操作系统字符串。当前可能的值为 dos (MS-DOS), win32 (Windows NTFS), darwin (OS X) 和默认值是 unix .
参数 spec_major :
放在这里少校 使用的 ZIP 规范中的版本号。
参数 spec_minor :
放在这里未成年人 使用的 ZIP 规范中的版本号。
返回:
返回 verMade .
获取操作系统:
function zip_version_get_os(verMade)
{
var tmp;
var ret;

tmp = (verMade & 0xFF00) >> 8;

switch (tmp) {
case 0x00:
ret = "dos";
break;
case 0x03:
ret = "unix";
break;
case 0x0A:
ret = "win32";
break;
case 0x13:
ret = "darwin";
break;
default:
ret = "unimplemented";
}

return ret;
}
用法:
参数 verMade :
verMade 放在这里值(value)。
返回:
以字符串形式返回操作系统。
获取主要版本号(ZIP 规范):
function zip_version_get_major(verMade)
{
return ((verMade & 0xFF) / 10);
}
用法:
参数 verMade :
verMade 放在这里值(value)。
返回:
从使用的 ZIP 规范返回主要版本。
获取次要版本号(ZIP 规范):
function zip_version_get_minor(verMade)
{
return ((verMade & 0xFF) % 10);
}
用法:
参数 verMade :
verMade 放在这里值(value)。
返回:
从使用的 ZIP 规范返回次要版本。

关于node.js - 如何计算 zip header 中 `version made by` 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64818467/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com