GZipStream's FileName should be set when constructing object #217

Open
opened 2026-01-29 22:08:33 +00:00 by claunia · 0 comments
Owner

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.

using (var outputStream = await file.OpenStreamForWriteAsync())
 {
          var bytes = new byte[DefaultBufferSize];
          int readBytes;
          while ((readBytes = stream.Read(bytes, 0, bytes.Length)) > 0)
          {
               await outputStream.WriteAsync(bytes, 0, readBytes, Token);
          }
}

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.

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. ``` using (var outputStream = await file.OpenStreamForWriteAsync()) { var bytes = new byte[DefaultBufferSize]; int readBytes; while ((readBytes = stream.Read(bytes, 0, bytes.Length)) > 0) { await outputStream.WriteAsync(bytes, 0, readBytes, Token); } } ``` 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.
claunia added the question label 2026-01-29 22:08:33 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#217