末尾のデータを含むgzipアーカイブがあります。 gzip -d
を使用して解凍すると、「解凍OK、後続のガベージは無視されます "(gzip -t
でも同じです。これは、あることを検出する方法として使用できます。そのようなデータ)。
今、私はこのゴミを知りたいのですが、不思議なことに、それを抽出する方法を見つけることができませんでした。 gzip -l --verbose
は、アーカイブの「圧縮された」サイズがファイルのサイズ(つまり、後続データを含む)であることを示していますが、これは誤りであり、役に立ちません。 file
も役に立たないので、どうすればよいですか?
末尾のデータを取得する方法を考え出した。
末尾のデータを含むファイルを作成するPerlスクリプトを作成しました。これは https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=604617#1 に基づいています。
#!/usr/bin/Perl
use strict;
use warnings;
use IO::Uncompress::Gunzip qw(:all);
use IO::File;
unshift(@ARGV, '-') unless -t STDIN;
my $input_file_name = shift;
my $output_file_name = shift;
if (! defined $input_file_name) {
die <<END;
Usage:
$0 ( GZIP_FILE | - ) [OUTPUT_FILE]
... | $0 [OUTPUT_FILE]
Extracts the trailing data of a gzip archive.
Outputs to stdout if no OUTPUT_FILE is given.
- as input file file causes it to read from stdin.
Examples:
$0 archive.tgz trailing.bin
cat archive.tgz | $0
END
}
my $in = new IO::File "<$input_file_name" or die "Couldn't open gzip file.\n";
gunzip $in => "/dev/null",
TrailingData => my $trailing;
undef $in;
if (! defined $output_file_name) {
print $trailing;
} else {
open(my $fh, ">", $output_file_name) or die "Couldn't open output file.\n";
print $fh $trailing;
close $fh;
print "Output file written.\n";
}