I am trying to unzip .gz file in c# using GZipStream as mentioned in this article
C# - How to read a text file from GZip
public static void ExtractGzip(string filePath)
{
using (FileStream reader = File.OpenRead(filePath))
using (GZipStream zip = new GZipStream(reader, CompressionMode.Decompress, true))
using (StreamReader unzip = new StreamReader(zip))
while (!unzip.EndOfStream)
Console.WriteLine(unzip.ReadLine());
}
Length of reader
Length of zip has an error, but ultimately the ReadLine() has only so much content and nothing more. I copy and paste it to a notepad all I see only the headers.
While there is still more data rows after this header, the endofstream is encountered just after the above.
The content of the .gz file is a .csv file with multiple records. The files are getting unzipped but only the first row of the csv zipped file(only the headers row) is getting retained in the output unzipped csv file.
I have tried multiple other ways to unzip gz files also including SharpZipLib and SharpCompress and also ZipArchive but none of these work correctly and result in an error, either 'No central directory found' etc.
The same .gz file can be unzipped correctly in python and all the data is retained but not in C#.
What is the cause of this issue, please anyone can throw some light on this would be very helpful.
Thanks in advance.


