Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/SharpCompress/IO/SeekableSharpCompressStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ public override void Rewind(bool stopRecording = false)
public override void StartRecording(int? minBufferSize = null) =>
_recordedPosition = _stream.Position;

public override void StopRecording() => _recordedPosition = null;
public override void StopRecording()
{
if (_recordedPosition.HasValue)
{
// Seek back to the recording anchor position, matching the behavior of the
// non-seekable SharpCompressStream.StopRecording() which rewinds _logicalPosition.
_stream.Seek(_recordedPosition.Value, SeekOrigin.Begin);
}
_recordedPosition = null;
}

protected override void Dispose(bool disposing)
{
Expand Down
30 changes: 30 additions & 0 deletions tests/SharpCompress.Test/GZip/GZipReaderAsyncTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
using SharpCompress.Common;
using SharpCompress.IO;
Expand Down Expand Up @@ -37,4 +38,33 @@ public async ValueTask GZip_Reader_Generic2_Async()
}
}
}

[Fact]
public async ValueTask GZip_ReaderFactory_FlatGZip_Async()
{
var source = new byte[2048];
for (var i = 0; i < source.Length; i++)
{
source[i] = 0xFF;
}

var gzipPath = Path.Combine(SCRATCH_FILES_PATH, "Flat.bin.gz");
using (var output = File.Create(gzipPath))
using (var gzip = new GZipStream(output, CompressionMode.Compress))
{
await gzip.WriteAsync(source, 0, source.Length);
}

using Stream stream = File.OpenRead(gzipPath);
await using var reader = await ReaderFactory.OpenAsyncReader(stream);
Assert.IsType<GZipReader>(reader);
Assert.True(await reader.MoveToNextEntryAsync());

using var ms = new MemoryStream();
await reader.WriteEntryToAsync(ms);
Assert.Equal(source.Length, ms.Length);
Assert.Equal(source, ms.ToArray());

Assert.False(await reader.MoveToNextEntryAsync());
}
}
6 changes: 6 additions & 0 deletions tests/SharpCompress.Test/GZip/GZipReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public void GZip_ReaderFactory_FlatGZip()
using var reader = ReaderFactory.OpenReader(stream);
Assert.IsType<GZipReader>(reader);
Assert.True(reader.MoveToNextEntry());

using var ms = new MemoryStream();
reader.WriteEntryTo(ms);
Assert.Equal(source.Length, ms.Length);
Assert.Equal(source, ms.ToArray());

Assert.False(reader.MoveToNextEntry());
}
}