Added explicit tar skip check. Caught skip issue.

This commit is contained in:
Adam Hathcock
2017-06-01 11:25:32 +01:00
parent 19c32aff6c
commit cff49aacba
2 changed files with 34 additions and 6 deletions

View File

@@ -143,7 +143,9 @@ namespace SharpCompress.Readers
private void Skip()
{
if (!Entry.IsSolid && Entry.CompressedSize > 0)
if (ArchiveType != ArchiveType.Rar
&& !Entry.IsSolid
&& Entry.CompressedSize > 0)
{
//not solid and has a known compressed size then we can skip raw bytes.
var rawStream = Entry.Parts.First().GetRawStream();
@@ -156,15 +158,14 @@ namespace SharpCompress.Readers
rawStream.Read(skipBuffer, 0, skipBuffer.Length);
}
rawStream.Read(skipBuffer, 0, (int)(bytesToAdvance % skipBuffer.Length));
return;
}
}
else //don't know the size so we have to try to decompress to skip
//don't know the size so we have to try to decompress to skip
using (var s = OpenEntryStream())
{
using (var s = OpenEntryStream())
while (s.Read(skipBuffer, 0, skipBuffer.Length) > 0)
{
while (s.Read(skipBuffer, 0, skipBuffer.Length) > 0)
{
}
}
}
}

View File

@@ -20,6 +20,33 @@ namespace SharpCompress.Test.Tar
Read("Tar.tar", CompressionType.None);
}
[Fact]
public void Tar_Skip()
{
using (Stream stream = new ForwardOnlyStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"))))
using (IReader reader = ReaderFactory.Open(stream))
{
ResetScratch();
int x = 0;
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
x++;
if (x % 2 == 0)
{
reader.WriteEntryToDirectory(SCRATCH_FILES_PATH,
new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}
}
}
}
[Fact]
public void Tar_BZip2_Reader()
{