I'm trying to download a .tar.gz file (which I will then uncompress.... but that's for later.)
I've hunted through CPAN, Stackoverflow, and Perl Monks, and the following snippit downloads the file & stores it on disk (and doesn't delete it until you hit enter for the <>
.)
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
<>;
Using wget
I get a file I can uncompress.
The above script saves a file..... which I can't open.
Both return files that are the same size, have the same md5sum
checksum, and appear to have the same first & last 64 bytes.....
What have I missed? How do I get this dang file?
Thanks...
(Perl:5.18.2; LWP::UserAgent:6.05; File::Temp:0.23)
****GGNNNNN*****
TIP - read the ACTUAL question!!!
The file being downloaded has the suffix .txt.gz
- it is NOT a tar
file. Using GUI tools to open it will work, because they don't make stupid assumptions and seamlessly select the correct tool for the job.
Files ending in txt.gz
need to be unpacked with gunzip
, not tar