Questions tagged [gzipstream]

GZipStream is a .NET 2.0+ class for compression and decompression using gzip format.

GZipStream is a .NET 2.0+ class for compression and decompression using gzip format., while including a redundancy check value for detecting data corruption. Compressed GZipStream object written to a .gz file can be decompressed using WinZip, 7zip, etc, but GZipStream does NOT provide functionality for adding or extracting files from .zip archives.

The compression functionality in DeflateStream and GZipStream is exposed as a stream. Data is read in on a byte-by-byte basis, so it is not possible to perform multiple passes to determine the best method for compressing entire files or large blocks of data. The DeflateStream and GZipStream classes are best used on uncompressed sources of data. If the source data is already compressed, using these classes may actually increase the size of the stream.

//Path to directory of files to compress and decompress.
string dirpath = @"c:\users\public\reports";

DirectoryInfo di = new DirectoryInfo(dirpath);

// Compress the directory's files.
foreach (FileInfo fi in di.GetFiles()){
    Compress(fi);
}

public static void Compress(FileInfo fi){
  // Get the stream of the source file.
  using (FileStream inFile = fi.OpenRead())
  {
    // Prevent compressing hidden and already compressed files.
    if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
       != FileAttributes.Hidden & fi.Extension != ".gz")
    {
      // Create the compressed file.
      using (FileStream outFile=File.Create(fi.FullName + ".gz"))
      {
          using (GZipStream Compress=new GZipStream(outFile,CompressionMode.Compress))
          {
              // Copy the source file into the compression stream.
              inFile.CopyTo(Compress);
              Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
                  fi.Name, fi.Length.ToString(), outFile.Length.ToString());
           }
       }
     }
  } 

http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

Do not confuse with that is a Java class.

319 questions
1
vote
0 answers

Deserialize JSON from Stream depending on first ~16 characters in .NET Core

I am getting a Gziped JSON which I check for a specific start string and if it's correct I deserialize into my object: await using var decompressionStream = new GZipStream(externalStream, CompressionMode.Decompress); var streamReader = new…
ThisWillDoIt
  • 380
  • 6
  • 24
1
vote
1 answer

VB.Net GZip compression is producing too much data and cannot be decoded

I am tring to compress an ascii string (base64) using GZip, however, it producing more data instead of less data. Can anyone help? It is an old project and I'm limited to the compilers and Framework versions. I have tried MSBuild 2.0, 3.5 & 4.0 -…
42LeapsOfFaith
  • 146
  • 1
  • 9
1
vote
1 answer

How to decompress text in Python that has been compressed with gzip?

How can you decompress a string of text in Python 3, that has been compressed with gzip and converted to base 64? For example, the text: EgAAAB+LCAAAAAAABAALycgsVgCi4vzcVAWFktSKEgC9n1/fEgAAAA== Should convert to: This is some text The following C#…
Geoff Smith
  • 585
  • 1
  • 5
  • 14
1
vote
0 answers

How to achieve minimum size when compressing small amount of data lossless?

I don’t understand the answer to ”Why does gzip/deflate compressing a small file result in many trailing zeroes?” (Why does gzip/deflate compressing a small file result in many trailing zeroes?) How would you go about compressing small amount of…
1
vote
1 answer

How to do GZIP compression while writing directly to response

I am trying to compress my response when the request header contains gzip in Accept-Encoding. However, adding following to app.properties only works when controller method is returning an…
1
vote
3 answers

How to do multithreaded compression / decompression with GZipStream without intermediate files on very large input

I want to write a program that does multithreaded compression / decompression using NET 3.5 and GZipStream library. The input files are very large (let's say hundreds of gigabytes) I would like to achieve this without having any intermediate…
1
vote
1 answer

how to deserialize GZipStream?

I am serializing a stream and it is being stored in cloud using REST services. Serialization part is given below- public void serialize(Object obj, Stream str) { using (GZipStream zipStream = new GZipStream(str, CompressionMode.Compress,…
1
vote
1 answer

IEnumerable, streams and WCF

I am writing a service that returns large sets of data to clients. Ideally, I want to return an IEnumerable of an Entity because I want the performance benefits of the laziness, both on the Service and Client. I also want to be able to compress the…
Paul Tsai
  • 893
  • 6
  • 16
1
vote
1 answer

Cannot append value to string C#

I've got two methods in my Windows Forms application for parsing some gzip encoded strings. Here are my two methods, which both return the same value. public static async Task DecodeGzipAsync(string str) { var values = new…
Brendan Gooden
  • 1,460
  • 2
  • 21
  • 40
1
vote
0 answers

How to receive udp-GELF message in gzip format via akka stream

I'm trying to write a program which listens to the specific port which another program send fake GELF message in UDP and gzips format on that. when the GELF message isn't gzipped It's easy to work with that, but when It's gzipped I don't know what…
navid
  • 95
  • 1
  • 10
1
vote
1 answer

GZipStream out of memory exception on decompression

I have a massive large dataset that contains almost 700 columns and I,m using GZipStream for compression and decompression. Compression works fine and size of the dataset after compression is almost 40mb, but I get "system out of memory" exception…
saadsaf
  • 1,421
  • 1
  • 17
  • 28
1
vote
2 answers

How to create a Gzip file without decompression?

I am using the below method to create a Gzip file by compressing the data. public static void GZipCompress(Stream dataToCompress, Stream outputStream) { GZipStream gzipStream = new GZipStream(outputStream,…
AnOldSoul
  • 4,017
  • 12
  • 57
  • 118
1
vote
1 answer

How do you unzip a gz file in memory using GZipStream?

I'm probably doing something obviously stupid here. Please point it out! I have some C# code that is pulling down a bunch of .gz files from SFTP (using the SSH.NET Nuget package - works great!). Each gz contains only a single .CSV file inside of…
Jaxidian
  • 13,081
  • 8
  • 83
  • 125
1
vote
1 answer

Unzipping a .gz file

I'm a student I'm trying to unzip a gz file but it gives following error message: Stating the magic number in GZip header is not correct, here is the code, I'really thannk full if any1 could let me know what mistake I'm doing FileInfo…
1
vote
1 answer

c# file compress with .gzip

I am trying to compress files with GZIP and my application monitors a folder for new files. When a new file comes in, it should be compressed and then application should continue doing this every time a new file comes in folder. private void…
maki
  • 37
  • 1
  • 1
  • 8