mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
GZipStream's FileName should be set when constructing object #220
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 @turbolocust on GitHub (Jul 15, 2017).
One issue I've found is that the FileName of GZipStream only is set after the first call of the Read() method. That should happen when constructing the object like it's implemented in the commons-compress library (written in Java) of Apache Foundation. The current behavior makes an object-oriented design more complicated.
In the example code above I'd have to rename the file after the loop or read the compressed file first, create the output file and then start to decompress the compressed file. The extract of the method shown above is defined in an abstract class.
@adamhathcock commented on GitHub (Jul 16, 2017):
Use GZipReader or GZipArchive if you want a nicer interface.
Streams are lower level and definitely logic like advancing the stream to load the file name shouldn’t happen in a constructor.
@turbolocust commented on GitHub (Jul 19, 2017):
I see. Again referring to commons-compress, the stream should be reset after reading the header. That's exactly what they do. There's an
init()method in the constructor which reads the header and resets its aggregated Inflater instance (as well as the CRC) afterwards. This way one can access the metadata right after creating the stream and that is much more useful in my opinion. Either way I'll look into this...@adamhathcock commented on GitHub (Jul 19, 2017):
You can’t read the stream then reset position because not all streams are seekable.
Dealing with non-seekable streams is a feature of the library.