Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am writing a program that will connect to a FTP server using LWP and d/l a zip compressed file. I am able to fetch the file, save it to disk, uncompress the file using Archive::Zip, and parse the resulting data.

The question I put before you is: How can I skip the save file to disk step and unzip the file directly from the UA's output? I understand that I can get a reference to $ua->content, but I haven't figured out how to pass that to a Archive::Zip object, which appears to only work on files and FHs.

This is the code I have right now, assume all objects were properly started before this snippit:

foreach my $file ( @filelist ) { my $FILE_URL = qq ( $URL/$file ); my $request = HTTP::Request->new(GET => $FILE_URL ); my $res = $ua->request($request, $file); print $res->status_line, "\n"; my $zip = Archive::Zip->new(); $zip->read ($file); my $member = $zip->memberNamed( 'data.dat' ); my ( $string, $status ) = $member->contents(); die "error $status" if $status != AZ_OK; print $string; }
This works, but saves the file to disk on line 4. I want to be able to take $ua->contents and use it for the zip file on line 8, $zip->read ($file).

Any help would be nice.

--SparkeyG
japh


In reply to LWP::UserAgent interaction w/ Archive::Zip by SparkeyG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found