本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipHelperStream.ReadDataDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# ZipHelperStream.ReadDataDescriptor方法的具体用法?C# ZipHelperStream.ReadDataDescriptor怎么用?C# ZipHelperStream.ReadDataDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipHelperStream
的用法示例。
在下文中一共展示了ZipHelperStream.ReadDataDescriptor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestArchive
/// <summary>
/// Test an archive for integrity/validity
/// </summary>
/// <param name="testData">Perform low level data Crc check</param>
/// <param name="strategy">The <see cref="TestStrategy"></see> to apply.</param>
/// <param name="resultHandler">The <see cref="ZipTestResultHandler"></see> handler to call during testing.</param>
/// <returns>true if all tests pass, false otherwise</returns>
/// <exception cref="ObjectDisposedException">The object has already been closed.</exception>
public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler)
{
if (isDisposed_) {
throw new ObjectDisposedException("ZipFile");
}
TestStatus status = new TestStatus(this);
if ( resultHandler != null ) {
resultHandler(status, null);
}
HeaderTest test = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header;
bool testing = true;
try {
int entryIndex = 0;
while ( testing && (entryIndex < Count) ) {
if ( resultHandler != null ) {
status.SetEntry(this[entryIndex]);
status.SetOperation(TestOperation.EntryHeader);
resultHandler(status, null);
}
try {
TestLocalHeader(this[entryIndex], test);
}
catch(ZipException ex) {
status.AddError();
if ( resultHandler != null ) {
resultHandler(status,
string.Format("Exception during test - '{0}'", ex.Message));
}
if ( strategy == TestStrategy.FindFirstError ) {
testing = false;
}
}
if ( testing && testData && this[entryIndex].IsFile ) {
if ( resultHandler != null ) {
status.SetOperation(TestOperation.EntryData);
resultHandler(status, null);
}
Crc32 crc = new Crc32();
using (Stream entryStream = this.GetInputStream(this[entryIndex]))
{
byte[] buffer = new byte[4096];
long totalBytes = 0;
int bytesRead;
while ((bytesRead = entryStream.Read(buffer, 0, buffer.Length)) > 0)
{
crc.Update(buffer, 0, bytesRead);
if (resultHandler != null)
{
totalBytes += bytesRead;
status.SetBytesTested(totalBytes);
resultHandler(status, null);
}
}
}
if (this[entryIndex].Crc != crc.Value) {
status.AddError();
if ( resultHandler != null ) {
resultHandler(status, "CRC mismatch");
}
if ( strategy == TestStrategy.FindFirstError ) {
testing = false;
}
}
if (( this[entryIndex].Flags & (int)GeneralBitFlags.Descriptor) != 0 ) {
ZipHelperStream helper = new ZipHelperStream(baseStream_);
DescriptorData data = new DescriptorData();
helper.ReadDataDescriptor(this[entryIndex].LocalHeaderRequiresZip64, data);
if (this[entryIndex].Crc != data.Crc) {
status.AddError();
}
if (this[entryIndex].CompressedSize != data.CompressedSize) {
status.AddError();
}
//.........这里部分代码省略.........
示例2: TestArchive
public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler)
{
if (this.isDisposed_)
{
throw new ObjectDisposedException("ZipFile");
}
TestStatus status = new TestStatus(this);
if (resultHandler != null)
{
resultHandler(status, null);
}
HeaderTest tests = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header;
bool flag = true;
try
{
for (int i = 0; flag && (i < this.Count); i++)
{
if (resultHandler != null)
{
status.SetEntry(this[i]);
status.SetOperation(TestOperation.EntryHeader);
resultHandler(status, null);
}
try
{
this.TestLocalHeader(this[i], tests);
}
catch (ZipException exception)
{
status.AddError();
if (resultHandler != null)
{
resultHandler(status, string.Format("Exception during test - '{0}'", exception.Message));
}
if (strategy == TestStrategy.FindFirstError)
{
flag = false;
}
}
if ((flag && testData) && this[i].IsFile)
{
if (resultHandler != null)
{
status.SetOperation(TestOperation.EntryData);
resultHandler(status, null);
}
Crc32 crc = new Crc32();
using (Stream stream = this.GetInputStream(this[i]))
{
int num3;
byte[] buffer = new byte[0x1000];
long num2 = 0L;
while ((num3 = stream.Read(buffer, 0, buffer.Length)) > 0)
{
crc.Update(buffer, 0, num3);
if (resultHandler != null)
{
num2 += num3;
status.SetBytesTested(num2);
resultHandler(status, null);
}
}
}
if (this[i].Crc != crc.Value)
{
status.AddError();
if (resultHandler != null)
{
resultHandler(status, "CRC mismatch");
}
if (strategy == TestStrategy.FindFirstError)
{
flag = false;
}
}
if ((this[i].Flags & 8) != 0)
{
ZipHelperStream stream2 = new ZipHelperStream(this.baseStream_);
DescriptorData data = new DescriptorData();
stream2.ReadDataDescriptor(this[i].LocalHeaderRequiresZip64, data);
if (this[i].Crc != data.Crc)
{
status.AddError();
}
if (this[i].CompressedSize != data.CompressedSize)
{
status.AddError();
}
if (this[i].Size != data.Size)
{
status.AddError();
}
}
}
if (resultHandler != null)
{
status.SetOperation(TestOperation.EntryComplete);
resultHandler(status, null);
}
}
//.........这里部分代码省略.........