I need to do this:
- unpack a file.7z
- 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:
- unpack file.7z (generates in_file that is extremely large)
- 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?
Advertisement
Answer
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 archive.zip -so | perl program.pl
Or you could use open
to get the unpacked information within the perl program:
my $archive_file = 'archive.zip'; 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