我正在尝试下载.tar.gz文件(然后将其解压缩....但这是以后使用的。)
我搜寻了CPAN,Stackoverflow和Perl Monks,下面的代码段下载了文件并将其存储在磁盘上(直到您按Enter才删除它<>
)。
use LWP::UserAgent;
use File::Temp;
# Create temporary file, and delete on script-exit
my $tmp = File::Temp->new( TEMPLATE => 'hathiXXXX', SUFFIX=>'.tar.gz', UNLINK=>1 );
my $uri = 'http://lucas.ucs.ed.ac.uk/test/hathi_full_20150701.txt.gz';
my $ua = LWP::UserAgent->new();
# Set the mime-type for a .tar.gz file
$ua->default_header('Accept' => 'application/x-gzip');
# ':content_file' => $tmp->filename is LWP magic to write to a file
my $res = $ua->get($uri, ':content_file' => $tmp->filename);
print $tmp->filename . "\n";
# Once you hit enter, the temporary file is deleted
<>;
使用wget
我可以解压缩的文件。上面的脚本保存了一个文件.....我无法打开。
这两个返回文件的大小均相同,md5sum
校验和也相同,并且前64个字节和后64个字节都相同.....
我错过了什么?我如何获得此dang文件?
谢谢...
(Perl:5.18.2; LWP :: UserAgent:6.05; File :: Temp:0.23)
**** GGNNNNN *****
提示-阅读实际问题!!!
正在下载的文件带有后缀.txt.gz
-不是tar
文件。使用GUI工具打开它会起作用,因为它们不会做出愚蠢的假设,而是无缝地选择正确的工具来完成工作。
结尾的文件txt.gz
需要用来解压gunzip
,而不是tar
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句