Skip to content

Commit

Permalink
Merge pull request #563 from adamhathcock/add-reader-test-gzip
Browse files Browse the repository at this point in the history
Fix Rewindable stream Length and add GZip Reader tests
  • Loading branch information
adamhathcock committed Jan 13, 2021
2 parents a28d686 + 1d8afb8 commit 4a7337b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/SharpCompress/IO/RewindableStream.cs
Expand Up @@ -84,11 +84,11 @@ public override void Flush()
throw new NotSupportedException();
}

public override long Length => throw new NotSupportedException();
public override long Length => stream.Length;

public override long Position
{
get { return stream.Position + bufferStream.Position - bufferStream.Length; }
get => stream.Position + bufferStream.Position - bufferStream.Length;
set
{
if (!isRewound)
Expand Down
6 changes: 3 additions & 3 deletions src/SharpCompress/SharpCompress.csproj
Expand Up @@ -2,9 +2,9 @@
<PropertyGroup>
<AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>0.27.0</VersionPrefix>
<AssemblyVersion>0.27.0</AssemblyVersion>
<FileVersion>0.27.0</FileVersion>
<VersionPrefix>0.27.1</VersionPrefix>
<AssemblyVersion>0.27.1</AssemblyVersion>
<FileVersion>0.27.1</FileVersion>
<Authors>Adam Hathcock</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
37 changes: 37 additions & 0 deletions tests/SharpCompress.Test/GZip/GZipReaderTests.cs
@@ -0,0 +1,37 @@
using System.IO;
using SharpCompress.Common;
using SharpCompress.IO;
using Xunit;

namespace SharpCompress.Test.GZip
{
public class GZipReaderTests : ReaderTests
{
public GZipReaderTests()
{
UseExtensionInsteadOfNameToVerify = true;
}

[Fact]
public void GZip_Reader_Generic()
{
Read("Tar.tar.gz", CompressionType.GZip);
}


[Fact]
public void GZip_Reader_Generic2()
{
//read only as GZip itme
using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")))
using (var reader = SharpCompress.Readers.GZip.GZipReader.Open(new RewindableStream(stream)))
{
while (reader.MoveToNextEntry()) // Crash here
{
Assert.NotEqual(0, reader.Entry.Size);
Assert.NotEqual(0, reader.Entry.Crc);
}
}
}
}
}

0 comments on commit 4a7337b

Please sign in to comment.