Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Write compressed data to file using Perl so it can be later uncompressed on the fly (as STDIN)

I'm looking for a combination of techniques to create a compressed file. Later I want to decompress that file on the fly and pass through pipe to the curl command.

The problem is the code I'm using produces a file that holds compressed data stream (as opposed to a file):

my $fh = IO::Zlib->new("file.gz", "wb9");
if (defined $fh) {
    print $fh "some big data here!\n";
    $fh->close;
}

Because of that I can't simply uncompress it using zcat:

zcat file.gz
zcat: can't stat: file.gz (file.gz.Z): No such file or directory

and the whole reason to do this is I was hoping to redirect zcat output as STDIN for curl command later:

zcat file.gz | curl -X PUT -d @- http://localhost:5822/

The above works if I create text file and gzip it. I was looking for an elegant way to do it from Perl, where I don't need to create temp file, zip it, delete temp file first.

This could be probably achieved in two ways:

1) find a way to create compressed file containing file data (as opposed to data stream)

2) find a Linux/Unix/OSX command that deals with files with stream compressed data (like zcat apparently can't)

Would be grateful for help re. both ways

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your Perl code works from my testing, with the addition of a necessary use line:

use IO::Zlib;

You say that your code produces a file that holds compressed data stream (as opposed to a file). That doesn't make any sense. A file is a file. It's an object in a file system holding a sequence of bytes. Your code generates an ordinary file, the contents of which is the compressed output of Zlib.

I believe your problem is either that the code is failing to generate the file for some reason (lack of permissions?) or you're simply looking in the wrong place for the file.

Add some debugging to see if the file is being successfully opened. Replace your "new" line with

my $fh = new IO::Zlib;
$fh->open("/full/path/to/filename", "wb9") or die("couldn't open file for writing: $!");

And use a full path with the file name so you can be sure of where the file is being generated. (Normally it would be created in the current directory, but it's not clear where that is without context)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!