Commit a8db46d0 authored by Keven's avatar Keven
Browse files

Rewrote file splitting in pure PHP

parent c9e45780
......@@ -140,19 +140,41 @@ class SendFile extends FileCommand
if ('@' === $path{0}) {
$path = substr($path, 1);
}
$destination = $path.'-';
$log = [];
$command = sprintf('split -d --verbose -b %s %s %s', $chunkSize, escapeshellarg($path), escapeshellarg($destination));
exec($command, $log, $status);
if (!is_readable($path)) {
return false;
}
if (!$size = filesize($path)) {
return false;
}
if (0 !== $status) {
if (false === $source = fopen($path, 'r')) {
return false;
}
preg_match_all('/creating file `([^\']+)/', implode('', $log), $matches);
$nbChunks = ceil($size/$chunkSize);
if (1 == $nbChunks) {
return [$path];
}
$chunks = [];
for ($i = 0 ; $i < $nbChunks ; $i++) {
if (false === $chunk = fopen($chunks[] = $path.'-'.$i, 'x')) {
fclose($source);
return false;
}
$bufferSize = 0;
while (!feof($source) and $bufferSize < $chunkSize) {
fwrite($chunk, fread($source, 4096));
$bufferSize += 4096;
}
fclose($chunk);
}
fclose($source);
return $matches[1];
return $chunks;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment