UnifiedArchive
UnifiedArchive copied to clipboard
one file driver: add memory efficient chunk read/write unpacking of gzip files
Previously the whole unpacked file was loaded into memory. This implementation allows to unpack gz files in a streamed way.
Quality Gate passed
Issues
2 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
btw, the above was tested successfully. possible implementation for the other two one-file-drivers (untested):
bzip:
/**
* @param string $targetPath
*/
public function streamToFile($targetPath)
{
$sfp = bzopen($this->fileName, 'rb');
$fp = fopen($targetPath, "w");
while (!feof($sfp)) {
$chunk = bzread($sfp, 8192);
if($chunk === 0 || $chunk === false)
throw new ArchiveExtractionException('Cannot read bzip chunk');
if(fwrite($fp, $chunk, strlen($chunk)) === false)
throw new ArchiveExtractionException('Cannot write bzip chunk');
}
bzclose($sfp);
fclose($fp);
}
lzma:
/**
* @param string $targetPath
*/
public function streamToFile($targetPath)
{
$sfp = xzopen($this->fileName, 'rb');
$fp = fopen($targetPath, "w");
while (!feof($sfp)) {
$chunk = xzread($sfp, 8192);
if($chunk === 0 || $chunk === false)
throw new ArchiveExtractionException('Cannot read xz chunk');
if(fwrite($fp, $chunk, strlen($chunk)) === false)
throw new ArchiveExtractionException('Cannot write xz chunk');
}
xzclose($sfp);
fclose($fp);
}
@wapmorgan please review when you can.
@wapmorgan any update on the above?
(untested):
somebody can test and create MR!