Download large shares file by file, resumably
A 29 GB share with 254 files failed as one ZIP: the single request ran into the 300-second request limit and, behind a proxy we cannot configure, could be cut at any time with no way to resume. Single-file downloads now answer HTTP Range requests (206, ETag and If-Range, 416 past the end): a SEALCHK2 file is decrypted from the chunk holding the first byte asked for. On that, the download page's new "Download all to a folder" (File System Access API, Chrome and Edge on a computer) saves every file into a folder the recipient picks, one request per file, in its folder path; a broken connection is retried from the byte on disk, complete files are skipped, and failed files get a Retry button. Other browsers keep the ZIP and the per-file buttons. The ZIP is sized up front with ZipStream's strict simulation and sent with Content-Length, so the browser shows progress and notices a cut. Both download routes lift the time limit for their streams. The recipient's download window now restarts with each download, so a long file-by-file download never outlasts it. The download page shows the file count and total size and marks the files this browser has downloaded, and the upload page gains "Browse Folder", which keeps each file's path as a dropped folder does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f9a7839ad3
commit
b594fb2300
@@ -200,20 +200,35 @@ class FileEncryptionService
|
||||
}
|
||||
|
||||
/**
|
||||
* The decrypted content of a file in any of the three formats, chunk by chunk.
|
||||
* The decrypted content of a file in any of the three formats, chunk by chunk, from byte
|
||||
* `$offset` of the plaintext on. A `SEALCHK2` file starts at the chunk holding that byte; the
|
||||
* older formats are decrypted from their start and the bytes before it dropped.
|
||||
*
|
||||
* @return Generator<int, string>
|
||||
*/
|
||||
public function decryptedChunks(string $encryptedPath, string $key): Generator
|
||||
public function decryptedChunks(string $encryptedPath, string $key, int $offset = 0): Generator
|
||||
{
|
||||
$magic = (string) file_get_contents($encryptedPath, false, null, 0, 8);
|
||||
|
||||
if ($magic === self::MAGIC) {
|
||||
yield from $this->decryptChunks($encryptedPath, $key);
|
||||
} elseif ($magic === self::LEGACY_CHUNKED_MAGIC) {
|
||||
yield from $this->decryptLegacyChunks($encryptedPath, $key);
|
||||
} else {
|
||||
yield $this->decryptLegacy($encryptedPath, $key);
|
||||
yield from $this->decryptChunks($encryptedPath, $key, $offset);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$chunks = $magic === self::LEGACY_CHUNKED_MAGIC
|
||||
? $this->decryptLegacyChunks($encryptedPath, $key)
|
||||
: [$this->decryptLegacy($encryptedPath, $key)];
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
if ($offset >= strlen($chunk)) {
|
||||
$offset -= strlen($chunk);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
yield substr($chunk, $offset);
|
||||
$offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +266,7 @@ class FileEncryptionService
|
||||
*
|
||||
* @return Generator<int, string>
|
||||
*/
|
||||
private function decryptChunks(string $encryptedPath, string $key): Generator
|
||||
private function decryptChunks(string $encryptedPath, string $key, int $offset = 0): Generator
|
||||
{
|
||||
$handle = fopen($encryptedPath, 'rb');
|
||||
|
||||
@@ -270,10 +285,16 @@ class FileEncryptionService
|
||||
throw new RuntimeException('Invalid encrypted file: no chunks');
|
||||
}
|
||||
|
||||
for ($index = 0; $index < $chunkCount; $index++) {
|
||||
$chunk = (string) fread($handle, $storedChunkSize);
|
||||
$firstIndex = min(intdiv($offset, max($chunkSize, 1)), $chunkCount - 1);
|
||||
$skip = $offset - $firstIndex * $chunkSize;
|
||||
fseek($handle, $this->chunkOffset($firstIndex, $chunkSize));
|
||||
|
||||
yield $this->decryptChunk($chunk, $key, $noncePrefix, $index, $index === $chunkCount - 1);
|
||||
for ($index = $firstIndex; $index < $chunkCount; $index++) {
|
||||
$chunk = (string) fread($handle, $storedChunkSize);
|
||||
$plaintext = $this->decryptChunk($chunk, $key, $noncePrefix, $index, $index === $chunkCount - 1);
|
||||
|
||||
yield $skip > 0 ? substr($plaintext, $skip) : $plaintext;
|
||||
$skip = 0;
|
||||
}
|
||||
} finally {
|
||||
fclose($handle);
|
||||
|
||||
Reference in New Issue
Block a user