murrayn has asked for the wisdom of the Perl Monks concerning the following question:

I need to "deflate" a data buffer and then embed that into another data stream before writing it out (I'm trying to write a bitmap into a new PNG file).

IO::Compress::Deflate appears to do the job and its doc says it "allows writing compressed data to files or buffer". All the methods and examples appear to write files. Am I wrong to interpret "buffer" as meaning an area of my program's working storage ($buffer)? Have I missed reading some crucial piece of documentation which should have been blindingly obvious? Am I using the wrong module altogether?

Replies are listed 'Best First'.
Re: Keeping deflated data in memory
by GrandFather (Saint) on Jun 28, 2016 at 04:51 UTC

    From the documentation:

    A scalar reference

    If $output_filename_or_reference is a scalar reference, the compressed data will be stored in $$output_filename_or_reference.
    Premature optimization is the root of all job security
Re: Keeping deflated data in memory
by pmqs (Friar) on Jun 28, 2016 at 13:12 UTC

    Here is an example of deflating from buffer ($data) and to a buffer. In this example $outbuffer will have the compressed data.

    use IO::Comnpress::Deflate = qw(deflate); my $data = "abcde"; my $outbuffer; deflate \$data => \$outbuffer;

Re: Keeping deflated data in memory
by Cow1337killr (Monk) on Jun 28, 2016 at 06:44 UTC

    I am not a graphics expert, but I Googled "perl png". Image::PNG was at the top.

    At the bottom of the documentation, the author gives a quick survey of all of the modules that he thought could possibly compete with his.

    (For example, Image::PNG::Rewriter may have some aspects that are similar to what you are working on.)

    Anyhow, I skimmed through the list and thought you might be interested, too.

    GD, by Lincoln D. Stein, was #3 in the Google search results; GD.pm is a Perl interface to Thomas Boutell's gd graphics library. Wikipedia says that Thomas Boutell was the editor of RFC 2083, PNG (Portable Network Graphics) Specification, Version 1.0.