Exemplo n.º 1
0
        public async Task DownloadExtractZipArchiveAsync(Download download, DirectoryInfo extractDirectory, DownloadProgress progress, CancellationToken cancellationToken)
        {
            var bytesTransferred = 0L;

            using var headResponse = await _options.HttpClient.SendAsync(new HttpRequestMessage (HttpMethod.Head, download.Archive.Url), cancellationToken);

            var contentLength = headResponse.Content.Headers.ContentLength ?? 0;
            var cacheFile     = new FileInfo(Path.Combine(_options.CacheDirectory.FullName, download.Archive.Url.Segments.Last()));

            await using var cacheStream = new FileStream(cacheFile.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
            var stopwatch = Stopwatch.StartNew();

            await using var httpStream  = new HttpStream(download.Archive.Url, cacheStream, ownStream: false, CachePageSize, cached: null);
            httpStream.RangeDownloaded += (_, args) =>
            {
                bytesTransferred += args.Length;
                progress.Report(new CopyProgress(stopwatch.Elapsed, 0, bytesTransferred, contentLength));
            };
            using var zipFile = new ZipFile(httpStream);
            var binaryRegex  = _options.Binaries[(download.Product, download.Platform)];