I want my perl script to load the binary data from a file. However this file can either be directly loaded or needs to be uncompressed (zlib) if the header _ISCOMPRESSED_ is present a the begining of the file.
I've been able to successfully load the uncompressed file and recognise the header:
(open my ($fh), "<", $fileName) or (return 0);
binmode $fh;
my $fileHeader;
sysread $fh, $fileHeader, 14;
if( $fileHeader eq "_ISCOMPRESSED_" ){
# Here, need to decompress the filestream and update the $fh to point toward uncompressed data
}
else{
# Read it from the begining
sysseek $fh,0,0;
}
# Read the data using the file handle
sysread $fh,$self->{'sig'},4;
sysread $fh,$self->{'version'},4;
I'd like now to decompress with Zlib the chunck of data and update the file handle $fh to dispense uncompressed data.
How should I do and is it possible to do it without writing the uncompressed data on disk?