コード例 #1
0
        private async Task Decompress(InternalPackageInformation info, ILocalBaseFolder localBaseFolder)
        {
            using (var stream =
                       localBaseFolder.OpenStreamForReading(PathForNugetPackage(info)))
                using (var compressed = new ZipArchive(stream, ZipArchiveMode.Read))
                {
                    var totalCount = compressed.Entries.Count;

                    foreach (var(zipArchiveEntry, i) in compressed.Entries.Select((e, i) => (e, i)))
                    {
                        var fullName = Uri.UnescapeDataString(zipArchiveEntry.FullName);
                        var name     = Uri.UnescapeDataString(zipArchiveEntry.Name);
                        listeners(new Decompressing(info.Package, info.Source, fullName, i, totalCount));

                        if (fullName.StartsWith("_rels") ||
                            name == "[Content_Types].xml")
                        {
                            continue;
                        }
                        // we skip over directory entries for now, assume we don't extract empty dirs
                        if ((zipArchiveEntry.ExternalAttributes & FolderBitmaskForZipArchiveEntry) == FolderBitmaskForZipArchiveEntry)
                        {
                            continue;
                        }

                        using (var fileStream = zipArchiveEntry.Open())
                            using (var outputStream =
                                       localBaseFolder.OpenStreamForWriting(Path.Combine(info.Package.OutputFolder, fullName)))
                            {
                                await fileStream.CopyToAsync(outputStream);
                            }
                    }
                }
        }