Skip to content

My process needs to read a file passed from the stream in order to save space (LINUX)

I need to do this:

  1. unpack a file.7z
  2. read the unpacked file and pass it to a perl process without writing it to disk

like this:

$unpack file.7z | perl_process > out_file

the process needs to read the unpacked file from the stream because it is very large and I need to save space.

currently I have (but can’t do) this:

  1. unpack file.7z (generates in_file that is extremely large)
  2. process in_file out_file (the process reads in_file and generates out_file)

Can you give me ideas of how could I achieve what I need?



So each archive contains exactly one file?

The 7z command-line program has an -so option that makes it send the unpacked output to STDOUT. That means you can send it through a pipe to your perl process:

$ 7z e -so | perl

Or you could use open to get the unpacked information within the perl program:

my $archive_file = '';

open my $archive_fh, '-|', "7z e $archive_file -so";

while ( <$archive_fh> ) {
    # Process text line

If you don’t already have a command-line version of 7zip then you should download p7zip which is described here

User contributions licensed under: CC BY-SA
5 People found this is helpful