Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

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 => "-"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://818831]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2018-02-22 05:22 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.