Download the zip file and unzip it to the internal storage. Android app Xamarin cross platform

Is there a way to download and unzip a file from a remote server using the Xamarin cross-platform application. I use PC: Storage librray to interact with files and folders.

IFolder rootFolder = FileSystem.Current.LocalStorage;
        IFolder folder = await rootFolder.CreateFolderAsync("MyAppRoot\\F1",CreationCollisionOption.OpenIfExists);
        IFile file = await folder.CreateFileAsync("firstfile.txt",
            CreationCollisionOption.ReplaceExisting);
        await file.WriteAllTextAsync("my content");

So I created the F1 folder inside the root folder of the application and creates the firstfile.txt files and write some additions to it. But how can I do the same with a zip file? Download the zip file, unzip the contents to a folder.

Also, how can I see folders / files created during application launch? Are any IsoStoreSpy tools available for the Xamarin android emulator?

+4
source share
1

, :

Xamarin

, /:

public static async Task<int> CreateDownloadTask(string urlToDownload, IProgress<DownloadBytesProgress> progessReporter)
{
int receivedBytes = 0;
int totalBytes = 0;
WebClient client = new WebClient();

using (var stream = await client.OpenReadTaskAsync(urlToDownload))
{
    byte[] buffer = new byte[4096];
    totalBytes = Int32.Parse(client.ResponseHeaders[HttpResponseHeader.ContentLength]);

    for (;;)
    {
        int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
        if (bytesRead == 0)
        {
            await Task.Yield();
            break;
        }

        receivedBytes += bytesRead;
        if (progessReporter != null)
        {
            DownloadBytesProgress args = new DownloadBytesProgress(urlToDownload, receivedBytes, totalBytes);
            progessReporter.Report(args);
        }
    }
}
return receivedBytes;
}

, , -

await zipFile.WriteAsync(buffer, 0, bytesRead);

, , Microsofts Compression NuGet, ... , DeflateStream System.IO.Compression .

- , .

0

All Articles