本文整理汇总了C#中System.IO.Compression.ZipArchive.GetEntryOrdinalIgnoreCase方法的典型用法代码示例。如果您正苦于以下问题:C# ZipArchive.GetEntryOrdinalIgnoreCase方法的具体用法?C# ZipArchive.GetEntryOrdinalIgnoreCase怎么用?C# ZipArchive.GetEntryOrdinalIgnoreCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.ZipArchive
的用法示例。
在下文中一共展示了ZipArchive.GetEntryOrdinalIgnoreCase方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenNuspecStreamAsync
public async Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
{
using (var nupkgStream = await OpenNupkgStreamAsync(package))
{
#if NET45
if (PlatformHelper.IsMono)
{
// Don't close the stream
var archive = Package.Open(nupkgStream, FileMode.Open, FileAccess.Read);
var partUri = PackUriHelper.CreatePartUri(new Uri(package.Id + ".nuspec", UriKind.Relative));
var entry = archive.GetPart(partUri);
using (var entryStream = entry.GetStream())
{
var nuspecStream = new MemoryStream((int)entryStream.Length);
await entryStream.CopyToAsync(nuspecStream);
nuspecStream.Seek(0, SeekOrigin.Begin);
return nuspecStream;
}
}
#endif
using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
{
var entry = archive.GetEntryOrdinalIgnoreCase(package.Id + ".nuspec");
using (var entryStream = entry.Open())
{
var nuspecStream = new MemoryStream((int)entry.Length);
await entryStream.CopyToAsync(nuspecStream);
nuspecStream.Seek(0, SeekOrigin.Begin);
return nuspecStream;
}
}
}
}
示例2: OpenNuspecStreamFromNupkgAsync
internal static async Task<Stream> OpenNuspecStreamFromNupkgAsync(
string id,
Task<Stream> openNupkgStreamAsync,
ILogger report)
{
using (var nupkgStream = await openNupkgStreamAsync)
{
try
{
using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
{
var entry = archive.GetEntryOrdinalIgnoreCase(id + ".nuspec");
using (var entryStream = entry.Open())
{
var nuspecStream = new MemoryStream((int)entry.Length);
#if DNXCORE50
// System.IO.Compression.DeflateStream throws exception when multiple
// async readers/writers are working on a single instance of it
entryStream.CopyTo(nuspecStream);
#else
await entryStream.CopyToAsync(nuspecStream);
#endif
nuspecStream.Seek(0, SeekOrigin.Begin);
return nuspecStream;
}
}
}
catch (InvalidDataException)
{
var fileStream = nupkgStream as FileStream;
if (fileStream != null)
{
report.LogWarning($"The ZIP archive {fileStream.Name.Yellow().Bold()} is corrupt");
}
throw;
}
}
}
示例3: OpenNuspecStreamAsync
public async Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
{
using (var nupkgStream = await OpenNupkgStreamAsync(package))
{
#if NET45
if (PlatformHelper.IsMono)
{
// Don't close the stream
var archive = Package.Open(nupkgStream, FileMode.Open, FileAccess.Read);
var partUri = PackUriHelper.CreatePartUri(new Uri(package.Id + ".nuspec", UriKind.Relative));
var entry = archive.GetPart(partUri);
using (var entryStream = entry.GetStream())
{
var nuspecStream = new MemoryStream((int)entryStream.Length);
await entryStream.CopyToAsync(nuspecStream);
nuspecStream.Seek(0, SeekOrigin.Begin);
return nuspecStream;
}
}
#endif
using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
{
var entry = archive.GetEntryOrdinalIgnoreCase(package.Id + ".nuspec");
using (var entryStream = entry.Open())
{
var nuspecStream = new MemoryStream((int)entry.Length);
#if NET45
await entryStream.CopyToAsync(nuspecStream);
#else
// System.IO.Compression.DeflateStream throws exception when multiple
// async readers/writers are working on a single instance of it
entryStream.CopyTo(nuspecStream);
#endif
nuspecStream.Seek(0, SeekOrigin.Begin);
return nuspecStream;
}
}
}
}
示例4: EnsureValidPackageContents
internal static void EnsureValidPackageContents(Stream stream, PackageInfo package)
{
var message = $"Response from {package.ContentUri} is not a valid NuGet package.";
try
{
using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true))
{
var entryName = $"{package.Id}.nuspec";
var entry = archive.GetEntryOrdinalIgnoreCase(entryName);
if (entry == null)
{
throw new InvalidDataException($"{message} Cannot find required entry {entryName}.");
}
}
}
catch (InvalidDataException e)
{
throw new InvalidDataException(message, innerException: e);
}
}
示例5: OpenRuntimeStreamFromNupkgAsync
internal static async Task<Stream> OpenRuntimeStreamFromNupkgAsync(PackageInfo package,
Func<PackageInfo, Task<Stream>> openNupkgStreamAsync,
IReport report)
{
using (var nupkgStream = await openNupkgStreamAsync(package))
{
try
{
using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
{
var entry = archive.GetEntryOrdinalIgnoreCase("runtime.json");
if (entry == null)
{
return null;
}
using (var entryStream = entry.Open())
{
var runtimeStream = new MemoryStream((int)entry.Length);
#if DNXCORE50
// System.IO.Compression.DeflateStream throws exception when multiple
// async readers/writers are working on a single instance of it
entryStream.CopyTo(runtimeStream);
#else
await entryStream.CopyToAsync(runtimeStream);
#endif
runtimeStream.Seek(0, SeekOrigin.Begin);
return runtimeStream;
}
}
}
catch (InvalidDataException)
{
var fileStream = nupkgStream as FileStream;
if (fileStream != null)
{
report.WriteLine("The ZIP archive {0} is corrupt",
fileStream.Name.Yellow().Bold());
}
throw;
}
}
}