XZStream doesn't support non-seekable streams #694

Open
opened 2026-01-29 22:16:02 +00:00 by claunia · 6 comments
Owner

Originally created by @montoner0 on GitHub (Aug 13, 2025).

XZStream tries to get a position from a stream and this isn't supported for non-seekable streams.

A simple repro:

using System.Net.Http;
using SharpCompress.Compressors.Xz;

new XZStream(await new HttpClient()
    .GetStreamAsync("https://deb.debian.org/debian/dists/bookworm/main/binary-amd64/Packages.xz"))
        .ReadByte();

will throw

System.NotSupportedException: Specified method is not supported.
   at System.Net.Http.HttpBaseStream.get_Position()
   at SharpCompress.Compressors.Xz.XZBlock..ctor(Stream stream, CheckType checkType, Int32 checkSize)
   at SharpCompress.Compressors.Xz.XZStream.NextBlock()
   at SharpCompress.Compressors.Xz.XZStream.ReadBlocks(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.Compressors.Xz.XZStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.ReadByte()
   at Program.<<Initialize>>d__0.MoveNext() in :line 5
Originally created by @montoner0 on GitHub (Aug 13, 2025). XZStream tries to get a position from a stream and this isn't supported for non-seekable streams. A simple repro: ``` using System.Net.Http; using SharpCompress.Compressors.Xz; new XZStream(await new HttpClient() .GetStreamAsync("https://deb.debian.org/debian/dists/bookworm/main/binary-amd64/Packages.xz")) .ReadByte(); ``` will throw ``` System.NotSupportedException: Specified method is not supported. at System.Net.Http.HttpBaseStream.get_Position() at SharpCompress.Compressors.Xz.XZBlock..ctor(Stream stream, CheckType checkType, Int32 checkSize) at SharpCompress.Compressors.Xz.XZStream.NextBlock() at SharpCompress.Compressors.Xz.XZStream.ReadBlocks(Byte[] buffer, Int32 offset, Int32 count) at SharpCompress.Compressors.Xz.XZStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.Stream.ReadByte() at Program.<<Initialize>>d__0.MoveNext() in :line 5 ```
Author
Owner

@Nanook commented on GitHub (Aug 14, 2025):

I'll look at this

@Nanook commented on GitHub (Aug 14, 2025): I'll look at this
Author
Owner

@adamhathcock commented on GitHub (Oct 13, 2025):

I think this was fixed by https://github.com/adamhathcock/sharpcompress/pull/930

@adamhathcock commented on GitHub (Oct 13, 2025): I think this was fixed by https://github.com/adamhathcock/sharpcompress/pull/930
Author
Owner

@montoner0 commented on GitHub (Oct 13, 2025):

I don't think so. v0.41.0 still crashes

@montoner0 commented on GitHub (Oct 13, 2025): I don't think so. v0.41.0 still crashes
Author
Owner

@adamhathcock commented on GitHub (Oct 14, 2025):

If you wrap the HttpResponseStream in a SharpCompressStream.Create it works. This new stream class handles some of the random access needed by certain compressions

@adamhathcock commented on GitHub (Oct 14, 2025): If you wrap the HttpResponseStream in a `SharpCompressStream.Create` it works. This new stream class handles some of the random access needed by certain compressions
Author
Owner

@montoner0 commented on GitHub (Oct 14, 2025):

Then I guess it should be documented somehow. It's quite not obvious.

And strictly speaking the issue is still valid since XZStream doesn't support such streams even though there's a workaround.

@montoner0 commented on GitHub (Oct 14, 2025): Then I guess it should be documented somehow. It's quite not obvious. And strictly speaking the issue is still valid since XZStream doesn't support such streams even though there's a workaround.
Author
Owner

@adamhathcock commented on GitHub (Oct 15, 2025):

I'm not saying it isn't an issue, it's just not documented as the way to do things is with the Reader/Writer/Archive interfaces.

From a basic search, XZ itself doesn't support forward only access in all scenarios.

@adamhathcock commented on GitHub (Oct 15, 2025): I'm not saying it isn't an issue, it's just not documented as the way to do things is with the Reader/Writer/Archive interfaces. From a basic search, XZ itself doesn't support forward only access in all scenarios.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#694