Eliminated "throw - catch all" logic in ZipArchive

This commit is contained in:
twirpx 2015-11-19 21:08:55 +05:00
parent 18bd810228
commit 0f12a073af
3 changed files with 12 additions and 13 deletions

View file

@ -116,7 +116,7 @@ namespace SharpCompress.Archive.Zip
try
{
ZipHeader header =
headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split);
headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x != null && x.ZipHeaderType != ZipHeaderType.Split);
if (header == null)
{
return false;

View file

@ -45,18 +45,17 @@ namespace SharpCompress.Common.Zip
lastEntryHeader = null;
uint headerBytes = reader.ReadUInt32();
header = ReadHeader(headerBytes, reader);
//entry could be zero bytes so we need to know that.
if (header.ZipHeaderType == ZipHeaderType.LocalEntry)
{
bool isRecording = rewindableStream.IsRecording;
if (!isRecording)
{
rewindableStream.StartRecording();
if (header != null) {
// entry could be zero bytes so we need to know that.
if(header.ZipHeaderType == ZipHeaderType.LocalEntry) {
bool isRecording = rewindableStream.IsRecording;
if (!isRecording) {
rewindableStream.StartRecording();
}
uint nextHeaderBytes = reader.ReadUInt32();
header.HasData = !IsHeader(nextHeaderBytes);
rewindableStream.Rewind(!isRecording);
}
uint nextHeaderBytes = reader.ReadUInt32();
header.HasData = !IsHeader(nextHeaderBytes);
rewindableStream.Rewind(!isRecording);
}
yield return header;
}

View file

@ -87,7 +87,7 @@ namespace SharpCompress.Common.Zip
return entry;
}
default:
throw new NotSupportedException("Unknown header: " + headerBytes);
return null;
}
}