diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index c99b667f..47a03461 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -1471,7 +1471,7 @@ private function exportFileData(File $file): void // Get the file size $fileSize = $file->getSize(); - if ($end > $fileSize) { + if ($end >= $fileSize) { $end = $fileSize - 1; } @@ -1495,7 +1495,7 @@ private function exportFileData(File $file): void $start += Transfer::STORAGE_MAX_CHUNK_SIZE; $end += Transfer::STORAGE_MAX_CHUNK_SIZE; - if ($end > $fileSize) { + if ($end >= $fileSize) { $end = $fileSize - 1; } } @@ -1704,8 +1704,8 @@ private function exportDeploymentData(Func $func, array $deployment): void $responseHeaders ); - // Content-Length header was missing, file is less than max buffer size. - if (!array_key_exists('Content-Length', $responseHeaders)) { + // content-length header missing, file is less than max buffer size + if (!array_key_exists('content-length', $responseHeaders)) { $file = $this->call( 'GET', "/functions/{$func->getId()}/deployments/{$deployment['$id']}/download", @@ -1714,7 +1714,7 @@ private function exportDeploymentData(Func $func, array $deployment): void $responseHeaders ); - $size = mb_strlen($file); + $size = strlen($file); if ($end > $size) { $end = $size - 1; @@ -1737,7 +1737,11 @@ private function exportDeploymentData(Func $func, array $deployment): void return; } - $fileSize = $responseHeaders['Content-Length']; + $fileSize = $responseHeaders['content-length']; + + if ($end >= $fileSize) { + $end = $fileSize - 1; + } $deployment = new Deployment( $deployment['$id'], @@ -1772,7 +1776,7 @@ private function exportDeploymentData(Func $func, array $deployment): void $start += Transfer::STORAGE_MAX_CHUNK_SIZE; $end += Transfer::STORAGE_MAX_CHUNK_SIZE; - if ($end > $fileSize) { + if ($end >= $fileSize) { $end = $fileSize - 1; } } @@ -1920,7 +1924,7 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void $responseHeaders ); - if (!\array_key_exists('Content-Length', $responseHeaders)) { + if (!\array_key_exists('content-length', $responseHeaders)) { $file = $this->call( 'GET', "/sites/{$site->getId()}/deployments/{$deployment['$id']}/download", @@ -1929,7 +1933,7 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void $responseHeaders ); - $size = mb_strlen($file); + $size = strlen($file); if ($end > $size) { $end = $size - 1; @@ -1951,7 +1955,11 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void return; } - $fileSize = $responseHeaders['Content-Length']; + $fileSize = $responseHeaders['content-length']; + + if ($end >= $fileSize) { + $end = $fileSize - 1; + } $siteDeployment = new SiteDeployment( $deployment['$id'], @@ -1982,7 +1990,7 @@ private function exportSiteDeploymentData(Site $site, array $deployment): void $start += Transfer::STORAGE_MAX_CHUNK_SIZE; $end += Transfer::STORAGE_MAX_CHUNK_SIZE; - if ($end > $fileSize) { + if ($end >= $fileSize) { $end = $fileSize - 1; } }