本文整理汇总了C#中PackageBuilder.GeneratePackageArchive方法的典型用法代码示例。如果您正苦于以下问题:C# PackageBuilder.GeneratePackageArchive方法的具体用法?C# PackageBuilder.GeneratePackageArchive怎么用?C# PackageBuilder.GeneratePackageArchive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PackageBuilder
的用法示例。
在下文中一共展示了PackageBuilder.GeneratePackageArchive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateArchiveDataFromPackage
private void GenerateArchiveDataFromPackage(PackageBuilder packageBuilder)
{
using (var archiveStream = new MemoryStream())
{
packageBuilder.GeneratePackageArchive(archiveStream);
_archiveData = archiveStream.ToArray();
}
}
示例2: TestRejectParentDirectoryEntry
public void TestRejectParentDirectoryEntry()
{
var builder = new PackageBuilder();
builder.AddFolder("..");
using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip")))
{
builder.GeneratePackageArchive(archiveStream);
archiveStream.Seek(0, SeekOrigin.Begin);
using (var extractor = new ZipExtractor(archiveStream, _sandbox))
extractor.Invoking(x => x.Run()).ShouldThrow<IOException>(because: "ZipExtractor must not accept archives with '..' as entry");
}
}
示例3: TestExtractToCustomDestination
public void TestExtractToCustomDestination()
{
var builder = new PackageBuilder()
.AddFile("emptyFile", new byte[] {});
using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip")))
{
builder.GeneratePackageArchive(archiveStream);
archiveStream.Seek(0, SeekOrigin.Begin);
const string message = "ZipExtractor should correctly extract empty files in an archive to custom destination";
using (var extractor = new ZipExtractor(archiveStream, _sandbox) {Destination = "custom"})
extractor.Invoking(x => x.Run()).ShouldNotThrow();
File.Exists(Path.Combine(_sandbox, "custom", "emptyFile")).Should().BeTrue(because: message);
File.ReadAllBytes(Path.Combine(_sandbox, "custom", "emptyFile")).Should().BeEmpty(because: message);
}
}
示例4: TestExtractToCustomDestination
public void TestExtractToCustomDestination()
{
var builder = new PackageBuilder()
.AddFile("emptyFile", new byte[] {});
using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip")))
{
builder.GeneratePackageArchive(archiveStream);
archiveStream.Seek(0, SeekOrigin.Begin);
const string message = "ZipExtractor should correctly extract empty files in an archive to custom destination";
using (var extractor = new ZipExtractor(archiveStream, _sandbox) {Destination = "custom"})
Assert.DoesNotThrow(() => extractor.Run());
Assert.IsTrue(File.Exists(new[] {_sandbox, "custom", "emptyFile"}.Aggregate(Path.Combine)), message);
Assert.AreEqual(new byte[] {}, File.ReadAllBytes(new[] {_sandbox, "custom", "emptyFile"}.Aggregate(Path.Combine)), message);
}
}