mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-30 06:55:16 -04:00
Write files in segments.
This commit is contained in:
parent
ab45b3072c
commit
694ababf15
1 changed files with 12 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
class Archive {
|
class Archive {
|
||||||
|
|
||||||
|
private static $SEGMENT_SIZE = 16777216; // 1024 * 1024 * 16 = 16MiB
|
||||||
private static $TAR_PASSTHRU_CMD = "cd [ROOTDIR] && tar --no-recursion -c -- [DIRS] [FILES]";
|
private static $TAR_PASSTHRU_CMD = "cd [ROOTDIR] && tar --no-recursion -c -- [DIRS] [FILES]";
|
||||||
private static $ZIP_PASSTHRU_CMD = "cd [ROOTDIR] && zip - -- [FILES]";
|
private static $ZIP_PASSTHRU_CMD = "cd [ROOTDIR] && zip - -- [FILES]";
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ class Archive {
|
||||||
|
|
||||||
// POSIX.1-1988 UStar implementation, by @TvdW
|
// POSIX.1-1988 UStar implementation, by @TvdW
|
||||||
|
|
||||||
|
set_time_limit(0);
|
||||||
$root_path = $this->app->get_abs_path();
|
$root_path = $this->app->get_abs_path();
|
||||||
|
|
||||||
// Build a list of filesizes so we can predict the total size
|
// Build a list of filesizes so we can predict the total size
|
||||||
|
@ -110,7 +112,16 @@ class Archive {
|
||||||
$file_header = substr_replace($file_header, $checksum, 148, 8);
|
$file_header = substr_replace($file_header, $checksum, 148, 8);
|
||||||
|
|
||||||
echo $file_header;
|
echo $file_header;
|
||||||
readfile($file);
|
|
||||||
|
// Send file content in segments to not hit PHP's memory limit (default: 128M)
|
||||||
|
if ($fd = fopen($file, 'rb')) {
|
||||||
|
while (!feof($fd)) {
|
||||||
|
print fread($fd, Archive::$SEGMENT_SIZE);
|
||||||
|
ob_flush();
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
fclose($fd);
|
||||||
|
}
|
||||||
|
|
||||||
$pad_file = 512 - ($size % 512);
|
$pad_file = 512 - ($size % 512);
|
||||||
if ($pad_file) echo str_repeat("\0", $pad_file);
|
if ($pad_file) echo str_repeat("\0", $pad_file);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue