mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add comments
This commit is contained in:
@@ -1111,20 +1111,30 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
|
||||
if ($size > APP_STORAGE_READ_BUFFER) {
|
||||
$buffer = '';
|
||||
$bytesRead = 0;
|
||||
|
||||
while ($bytesRead < $size) {
|
||||
// Determine how many bytes to read in this iteration
|
||||
$bytesToRead = min(APP_STORAGE_READ_BUFFER, $size - $bytesRead);
|
||||
|
||||
// Read data from the device and append to the buffer
|
||||
$buffer .= $deviceFiles->read($path, $bytesRead, $bytesToRead);
|
||||
$bytesRead += $bytesToRead;
|
||||
|
||||
// Process the buffer in chunks of output size
|
||||
while (strlen($buffer) >= MAX_OUTPUT_CHUNK_SIZE) {
|
||||
// Send an output chunk of specified size
|
||||
$response->chunk(substr($buffer, 0, MAX_OUTPUT_CHUNK_SIZE), false);
|
||||
// Remove the sent chunk from the buffer
|
||||
$buffer = substr($buffer, MAX_OUTPUT_CHUNK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
// Send any remaining data as a final chunk
|
||||
if (strlen($buffer) > 0) {
|
||||
$response->chunk($buffer, true);
|
||||
}
|
||||
} else {
|
||||
// If the file is smaller than the buffer size, read and send the whole file
|
||||
$response->send($deviceFiles->read($path));
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user