0

I'm using the below code to compress byte[] using gzip stream class. How do I return a file with ".gz" name? Suppose we have a csv file and want a new file with ".csv.gz". Should I use write all File.WriteAll bites method?

public byte[] gZipCompress(byte[] data)
{
    using (MemoryStream outStream = new MemoryStream())
    {
        using (GZipStream gzipStream = new GZipStream(outStream, CompressionMode.Compress))
        using (MemoryStream srcStream = new MemoryStream(data))
        {
            srcStream.CopyTo(gzipStream);
        }
        return outStream.ToArray();
    }
}
urmat abdykerimov
  • 415
  • 1
  • 6
  • 16

0 Answers0