Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda