Reputation: 772
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
Upvotes: 3
Views: 785
Reputation: 352
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)
Upvotes: 2