Open proconsule opened 2 years ago
Since we are implementing the stream function, we can do the following.
$file = __DIR__ . '/data';
// compress
copy(PHP_BINARY, 'compress.zstd://' . $file);
// decompress
$out = '';
$fp = fopen('compress.zstd://' . $file, 'r');
if ($fp) {
while($in = fread($fp, 4096)) {
$out .= $in;
}
fclose($fp);
}
But the stream handler does not help when e.g. trying to decompress a very large zstd compressed document with a custom dictionary.
I found out that is impossible to decompress form a file handler reading chunks.
I have a very big file that have compressed data starting from an offset. i have a file handler and seek to the start of compressed data it will be very very useful for me (and for many others i think) a function that can get the file handler and read chunks of data outputing the uncompressed data
like
$this->fh = fopen("FILE",'r'); fseek($this->fh,$this->offset); //the start of compressed data
$zstd_object = zstd_uncompress_handler($this->fh);
while(EOF or some condition){ $outdata = $zstd_object->uncompress($chunksize); //just an idea of object function // Data here can be printed or anything else (for a on the fly download and so on) }
This can be done and you think can be usefull? (if so i'll use for sure on my project)