Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Gzip inflate a variable

by rkrieger (Friar)
on Jan 21, 2010 at 22:33 UTC ( #818831=note: print w/ replies, xml ) Need Help??


in reply to Gzip inflate a variable

You use 'inflate', whereas I believe the gzip man page mentions 'deflate' for the compression mode. Did I misunderstand? I suspect compress/deflate is analogous to making a balloon smaller by deflating it.

Assuming you want to send out content in gzip'ed form and the images are static, you may want to place them in a separate directory, serve them from a lightweight process (thttpd, nginx, or a lean apache) or behind a proxy server (squid, varnish, pound, whichever you prefer). Granted, that's a non-programming solution which may not fit your case.

For storing gzip'ed data, I suppose IO::Compress::Gzip would allow you to gzip() to store to a scalar reference.

Shamelessly stolen from the synopsis and altered off-the-cuff:

use IO::Compress::Gzip qw(gzip $GzipError); my $gzip_data; my $status = gzip $input => \$gzip_data [,OPTS] or die "gzip failed: $GzipError\n";

Would this be what you're looking for? I suppose it's not too difficult to send out $gzip_data to a HTTP client end of the Perl code. Or did I simply mistake what you're trying to do?


Comment on Re: Gzip inflate a variable
Select or Download Code
Replies are listed 'Best First'.
Re^2: Gzip inflate a variable
by MonkDrew (Initiate) on Jan 21, 2010 at 22:42 UTC
    Yeah, you are right... sorry. Your analogy makes sense now. Basically my perl script is the entire HTTP server, so it handles accessing the filesystem and caching. So I guess using your example I can have the contents of the image in variable $foo. Then do:
    use IO::Compress::Gzip qw(gzip $GzipError); my $compressed; if(gzip $foo => \$compressed [,OPTS]){ # Compressed version of $foo stored in $compressed }
      That's not quite correct. To read from a variable and write to a variable you need to add a backslash to both the input & output variables
      use IO::Compress::Gzip qw(gzip $GzipError); my $compressed; if(gzip \$foo => \$compressed [,OPTS]){ # Compressed version of $foo stored in $compressed }
      If you want the output to go to a filehandle
      # assume $fh is a filehandle ... gzip \$foo => $fh
      If you want to send the output to standard output, use "-"
      gzip \$foo => "-"
      Paul

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://818831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2015-07-30 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls