java - 为什么 GZIP "os" header 在 Java 中被硬编码为 FAT?

标签 java gzip

RFC 1952 2.3.1 节指定 GZIP header 必须包含 OS 标志:

OS (Operating System). This identifies the type of file system on which compression took place. This may be useful in determining end-of-line convention for text files. The currently defined values are as follows:

  0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)
  1 - Amiga
  2 - VMS (or OpenVMS)
  3 - Unix
  4 - VM/CMS
  5 - Atari TOS
  6 - HPFS filesystem (OS/2, NT)
  7 - Macintosh
  8 - Z-System
  9 - CP/M
 10 - TOPS-20
 11 - NTFS filesystem (NT)
 12 - QDOS
 13 - Acorn RISCOS
255 - unknown

但是,Java 的 GZIP 序列化在所有情况下都写入零,如在 line 193 of GzipOutputStream.java 中所见。 .我在四个不同的操作系统上运行了测试,以确认没有其他代码在编写后修改此 header 。

为什么这个值是硬编码的?

最佳答案

正如 Elliott 所指出的,根据您引用的同一 RFC 的第 2.3.1.2 节,将其设置为默认值是可以的:

A compliant compressor must produce files with correct ID1, ID2, CM, CRC32, and ISIZE, but may set all the other fields in the fixed-length part of the header to default values (255 for OS, 0 for all others). The compressor must set all reserved bits to zero.

但是,根据这个片段,默认值仍然不正确 - OS 标志的默认值是 255,而不是 0。这是一个已知错误根据 JDK-8244706 的 JDK .它已在 Java 版本 16,抢先体验版本 16 中修复。

关于java - 为什么 GZIP "os" header 在 Java 中被硬编码为 FAT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61715912/

相关文章:

c# - 使用 C# 使用 GZipStream 类对包含子目录的目录进行 Gzip 压缩?

Java:使用新对象时两种方式的不同

java - 为什么我不能使用 "instanceof"作为 Int 和 Integer 的比较数组?

python - Docker python客户端API拷贝

html - 我可以 gzip 压缩我所有的 html 内容(页面)吗?

javascript - 使用 JavaScript 将 blob 添加到 tar 并流式传输到服务器

java - 如何在Excel中导出网页

java - 在范围之间添加一个数字

java - 每个帐户可以创建多少个 Flurry 项目?

c# - 是否可以 gzip 自动包含的脚本?