Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

GZip decompression fails when reading from non-seekable streams (e.g., HttpClient.GetStreamAsync()) because GZipFilePart unconditionally accesses stream.Position, which throws NotSupportedException on HTTP streams.

Changes

  • GZipFilePart.cs: Check stream.CanSeek before accessing Position. Set EntryStartPosition = 0 for non-seekable streams since they read sequentially from current position.

  • GZipArchiveEntry.cs: Check CanSeek before attempting position reset in OpenEntryStream().

  • Test coverage: Added GZip_Archive_NonSeekableStream test using a NonSeekableStream wrapper to verify the fix.

Usage

// Now works with HTTP streams
using var httpStream = await httpClient.GetStreamAsync(gzipUrl);
using var reader = GZipReader.Open(httpStream);
while (reader.MoveToNextEntry())
{
    reader.WriteEntryTo(outputStream);
}

Note: GZipReader supports non-seekable streams. GZipArchive.Open() continues to require seekable streams by design.

Original prompt

This section details on the original issue you should resolve

<issue_title>HttpBaseStream Gzip extract - NotSupportedException</issue_title>
<issue_description>Hi, looks like when trying to decompress a gzip through httpStream it throws NotSupportedException on Position when setting EntryStartPosition. what is the purpose of settings this field? how can i mitigate the problem? Thanks!

System.NotSupportedException: Specified method is not supported.
   at System.Net.Http.HttpBaseStream.get_Position()
   at SharpCompress.IO.RewindableStream.get_Position()
   at SharpCompress.Common.GZip.GZipFilePart..ctor(Stream stream, ArchiveEncoding archiveEncoding)
   at SharpCompress.Common.GZip.GZipEntry.GetEntries(Stream stream, OptionsBase options)+MoveNext()

P.S i'd prefer to not save the file to disk and read it again as FileStream if possible
If that's not possible which types require random access? i know that .tar.gz works perfectly fine through http for example, Thanks in advance!</issue_description>

Comments on the Issue (you are @copilot in this section)

@adamhathcock You'll have to show me how you're calling things.

GZipFilePart does check CanSeek but Rewindable is meant to buffer unbufferable streams so shouldn't be used here.</comment_new>
<comment_new>@adamhathcock
Actually, I take that back, GZipFilePart has a usage of Position no matter seeking. That should be changed</comment_new>
<comment_new>@adamhathcock
you're right but I'm not sure why I'm doing that....I'd have to look and remember</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits October 27, 2025 11:02
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
- Modified GZipFilePart to only access stream.Position when stream.CanSeek is true
- Modified GZipArchiveEntry.OpenEntryStream to check CanSeek before accessing Position
- Added test case GZip_Archive_NonSeekableStream to verify non-seekable stream support
- All existing tests pass

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix NotSupportedException in HttpBaseStream Gzip extraction Fix GZip extraction NotSupportedException for non-seekable streams Oct 27, 2025
Copilot AI requested a review from adamhathcock October 27, 2025 11:15
@adamhathcock adamhathcock marked this pull request as ready for review October 27, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpBaseStream Gzip extract - NotSupportedException

2 participants