I've been stuck for awhile trying to uncompress .Z text files on the fly. I have a series of files to get off the company's intranet some are straight text files and some have been compressed.
The plain text files are simple using LWP and just loading the content into a variable to then playing with it. I've not been able to get the compressed files to uncompress nicely.
I've been trying to use the Compress::Zlib module. A snippet of the appropriate code follows:
use Compress::Zlib;
use LWP::UserAgent;
use HTTP::Request;
use strict;
....etc.
my $ua = new LWP::UserAgent;
$ua->proxy('http', 'http://some.proxy.com:8000/');
my $file = "somefile.Z";
my $page="http://somehost.com/$file";
my $request = new HTTP::Request("GET", $page);
my $response = $ua->request($request);
if($response->is_success && $response->header('Content-Encoding') =
+~ /compress/){
$stuff = Compress::Zlib::uncompress($response->content_ref);
}
play with data...
Basically $stuff is undef. If I use the inflate process provided in Compress::Zlib
I get a status of Z_DATA_ERROR (-3). I don't see why the returned content shouldn't
just decompress. I've checked the files and they are properly x-compressed. What am I missing?
Does the web client not return the compressed file properly? Help!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.