How to create a gzip file w/ FEXTRA & FCOMMENT fields

不想你离开。 提交于 2020-12-13 04:45:29

问题


I have a need to test if a program that I'm writing is parsing the gzip header correctly, and that includes reading the FEXTRA, FNAME, and FCOMMENT fields. Yet it seems that gzip doesn't support creating archives with the FEXTRA and FCOMMENT fields -- only FNAME. Are there any existing tools which can do all three of these?


回答1:


The Perl module IO::Compress::Gzip optionally lets you set the three fields you are intrested in. (Fair disclosure: I am the author of the module)

Here is some sample code that sets FNAME to "filename", FCOMMENT to "This is a comment" and creates an FEXTRA field with a single subfield with ID "ab" and value "cde".

use IO::Compress::Gzip qw(gzip $GzipError);

gzip \"payload" => "/tmp/test.gz", 
     Name       => "filename", 
     Comment    => "This is a comment", 
     ExtraField => [ "ab" => "cde"] 
  or die "Cannot create gzip file: $GzipError" ;

And here is a hexdump of the file it created.

00000000  1f 8b 08 1c cb 3b 3a 5a  00 03 07 00 61 62 03 00  |.....;:Z....ab..|
00000010  63 64 65 66 69 6c 65 6e  61 6d 65 00 54 68 69 73  |cdefilename.This|
00000020  20 69 73 20 61 20 63 6f  6d 6d 65 6e 74 00 2b 48  | is a comment.+H|
00000030  ac cc c9 4f 4c 01 00 15  6a 2c 42 07 00 00 00     |...OL...j,B....|
0000003f


来源:https://stackoverflow.com/questions/47894136/how-to-create-a-gzip-file-w-fextra-fcomment-fields

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!