mirror of
https://github.com/splitbrain/php-archive.git
synced 2025-01-17 05:28:25 +01:00
Tar::addFile(): use larger read buffer for better performance
This commit is contained in:
parent
f931cad249
commit
f15ef3a95c
19
src/Tar.php
19
src/Tar.php
@ -319,16 +319,27 @@ class Tar extends Archive
|
|||||||
throw new ArchiveIOException('Could not open file for reading: ' . $file);
|
throw new ArchiveIOException('Could not open file for reading: ' . $file);
|
||||||
}
|
}
|
||||||
while (!feof($fp)) {
|
while (!feof($fp)) {
|
||||||
$data = fread($fp, 512);
|
// try to read 1 MB (512 bytes is unperformant)
|
||||||
$read += strlen($data);
|
$data = fread($fp, 1048576);
|
||||||
if ($data === false) {
|
if ($data === false) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($data === '') {
|
if ($data === '') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$packed = pack("a512", $data);
|
$dataLen = strlen($data);
|
||||||
$this->writebytes($packed);
|
$read += $dataLen;
|
||||||
|
// how much of data read fully fills 512-byte blocks?
|
||||||
|
$passLen = ($dataLen >> 9) << 9;
|
||||||
|
if ($passLen === $dataLen) {
|
||||||
|
// all - just write the data
|
||||||
|
$this->writebytes($data);
|
||||||
|
} else {
|
||||||
|
// directly write what fills 512-byte blocks fully
|
||||||
|
$this->writebytes(substr($data, 0, $passLen));
|
||||||
|
// pad the reminder to 512 bytes
|
||||||
|
$this->writebytes(pack("a512", substr($data, $passLen)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user