Repository: symfony/symfony
File: src/Symfony/Component/Translation/Bridge/Lokalise/LokaliseProvider.php (PHP)

Code before:
                'export_empty_as' => 'skip',
                'replace_breaks' => false,
            ],
        ]);

        if (200 !== $response->getStatusCode()) {
            throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
        }

        $processId = $response->toArray()['process_id'];
        $attempt = 0;
        while (true) {
            $response = $this->client->request('GET', \sprintf('processes/%s', $processId));
            $process = $response->toArray()['process'];
            if (\in_array($process['status'], self::FAILED_PROCESS_STATUS, true)) {
                throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
            }
            if (self::SUCESS_PROCESS_STATUS === $process['status']) {
                $downloadUrl = $process['details']['download_url'];
                break;
            }
            ++$attempt;
            usleep(500000 * $attempt);
        }

        $response = $this->client->request('GET', $downloadUrl, ['buffer' => true]);
        if (200 !== $response->getStatusCode()) {
            throw new ProviderException(\sprintf('Unable to download translations file from Lokalise: "%s".', $response->getContent(false)), $response);
        }
        $newfile = \sprintf('%s%s%s.zip', sys_get_temp_dir(), \DIRECTORY_SEPARATOR, uniqid());
        $extractPath = \sprintf('%s%s%s', sys_get_temp_dir(), \DIRECTORY_SEPARATOR, uniqid());
        try {
            $fileHandler = fopen($newfile, 'w');
            foreach ($this->client->stream($response) as $chunk) {
                fwrite($fileHandler, $chunk->getContent());
            }
            fclose($fileHandler);

            $zip = new \ZipArchive();
            if (!$zip->open($newfile, \ZipArchive::CREATE)) {
                throw new LogicException(\sprintf('failed to open zip file "%s".', $newfile));
            }

            try {
                if (!$zip->extractTo($extractPath)) {
                    throw new LogicException(\sprintf('failed to extract content from zip file "%s".', $newfile));
                }
            } finally {
                $zip->close();
            }


Review comment (suggestion):
no need to buffer since we write by chunk:
```suggestion
        $response = $this->client->request('GET', $downloadUrl, ['buffer' => false]);
```

(the alternative would be to pass a file handler instead of a boolean, then wait for the last chunk below, but it's also fine as you wrote it)

Code after:
                'replace_breaks' => false,
            ],
        ]);

        if (200 !== $response->getStatusCode()) {
            throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
        }

        $processId = $response->toArray()['process_id'];
        while (true) {
            $response = $this->client->request('GET', \sprintf('processes/%s', $processId));
            $process = $response->toArray()['process'];
            if (\in_array($process['status'], self::FAILED_PROCESS_STATUS, true)) {
                throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
            }
            if (self::SUCESS_PROCESS_STATUS === $process['status']) {
                $downloadUrl = $process['details']['download_url'];
                break;
            }
            usleep(500000);
        }

        $response = $this->client->request('GET', $downloadUrl, ['buffer' => false]);
        if (200 !== $response->getStatusCode()) {
            throw new ProviderException(\sprintf('Unable to download translations file from Lokalise: "%s".', $response->getContent(false)), $response);
        }
        $zipFile = tempnam(sys_get_temp_dir(), 'lokalise');
        $extractPath = $zipFile.'.dir';
        try {
            if (!$h = @fopen($zipFile, 'w')) {
                throw new RuntimeException(error_get_last()['message'] ?? 'Failed to create temporary file.');
            }
            foreach ($this->client->stream($response) as $chunk) {
                fwrite($h, $chunk->getContent());
            }
            fclose($h);

            $zip = new \ZipArchive();
            if (!$zip->open($zipFile)) {
                throw new RuntimeException('Failed to open zipped translations from Lokalise.');
            }

            try {
                if (!$zip->extractTo($extractPath)) {
                    throw new RuntimeException('Failed to unzip translations from Lokalize.');
                }
            } finally {
                $zip->close();
            }

            return $this->getZipContents($extractPath);