mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
DeflateStream.Length throws NotSupportedException #255
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @evil-shrike on GitHub (Oct 26, 2017).
Is it by design?
Why DeflateStream can't return its Length?
This DeflateStream is actually picked up from zipArchive.Entries by name:
That
contentEntryhas Size property. But stream returned byOpenEntryStream(DeflateStream) throws on reading itsLengthproperty.I can guess while it's happening (probably because ZipArchiveEntry.Size is extracted from metadata) but it's inconvenient. Because it means I can't return Stream in my API (not bound to the lib) - as it can throws.
I'd suggest to make that Stream make safe and not to throw in
Length.@adamhathcock commented on GitHub (Oct 26, 2017):
That is by design. Most streams aren't seekable in this API so you can't just do Stream.Length. This is because very large archives or archives based on network streams are a primary use-case.
@evil-shrike commented on GitHub (Oct 26, 2017):
Ok, in general it makes sense (one should check CanSeek before calling
Stream.Length), but in this case Size is known...@adamhathcock commented on GitHub (Oct 26, 2017):
The size isn't always known. The source of the data could be a stream that isn't seekable. Sometimes, size isn't known on a zip archive if it was created in a streaming manner.
There could be work done to know the stream size in some cases but I haven't put the work in to do that. Just don't do Stream.Length. Why do you need that?