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
2
votes
1 answer

Decompressing GZip Json String into normal Json String in Angularjs+Typescript

Our application is built in Angularjs, In one scenario We are sending good amount of JSON data to client side. So it take much time. So What we have done now, we make that JSON data as GZIP string. public static string Compress(string s) { …
Constant Learner
  • 525
  • 4
  • 13
  • 30
2
votes
1 answer

how to get a byte array or readable stream from a GZipStream

I would like to write a compressed version of a byte array to a SQL Server varbinary(max) column. I would like to feed the parameter of the SqlClient's command a SqlBytes type, and have tried to instantiate that type so: // data is a byte array at…
Tim
  • 8,669
  • 31
  • 105
  • 183
2
votes
2 answers

Correct way to use GZipStream in dotNET C#

I'm working with GZipStream at the moment using .net 3.5. I have two methods listed below. As input file I use text file which consists of chars 's'. Size of the file is 2MB. This code works fine if I use .net 4.5 but with .net 3.5 after compress…
Leo
  • 1,683
  • 2
  • 20
  • 25
2
votes
1 answer

C++/zlib/gzip compression and C# GZipStream decompression fails

I know there's a ton of questions about zlib/gzip etc but none of them quite match what I'm trying to do (or at least I haven't found it). As a quick overview, I have a C# server that decompresses incoming strings using a GZipStream. My task is to…
briansyph
  • 150
  • 11
2
votes
1 answer

I'm attempting to force gzip compression on a page using GZipStream but the browser says I'm using unsupported compression

I'm tring to implement what Steve Souders discusses http://www.stevesouders.com/blog/2010/07/12/velocity-forcing-gzip-compression/ about forcing gzip compression I've got a module that's running this: void context_PreSendRequestHeaders(object…
Glenn Slaven
  • 33,720
  • 26
  • 113
  • 165
2
votes
0 answers

Zipped file contains multiple files. How to Read / Process them in Java Buffer in a loop

I have a Big Zipped File which in turn have 100's of small files in it. How can I unzip them (although I am doing it with GZIP already), and read into Java buffer one by one in a loop or some thing. So basically, using GZIP I can unzip a file in…
Noman K
  • 277
  • 1
  • 5
  • 15
2
votes
4 answers

Gzip compression for HTTP requests

Is there any way to make browsers &/or Silverlight application do a GZIP compression of HTTP requests? Don't confuse with GZIP compression of HTTP responses - I know how to set this up on the server side. What I need is to compress requests as well,…
Michael Pliskin
  • 2,352
  • 4
  • 26
  • 42
2
votes
2 answers

Why is my programmatic compression dropping the file extension?

I am using C# to programatically compress an xml file. Compression works fine, but when I gunzip the file from the command line, the extension has been dropped. Why would this be? The destination file coming in has the gz extension while the…
sidd.darko
  • 79
  • 7
2
votes
1 answer

Chrome not unzipping gzip file if the gzip file was created by combining multiple gzip files

I am creating two gzip files, one which contains only a single gzip member, where as the second one contains 2 gzip members (two files concatenated into a single gzip file). When I try to download this through a web server, chrome decompresses the…
Izaaz Yunus
  • 2,828
  • 1
  • 19
  • 28
2
votes
3 answers

Loading specific section of a compressed file stream

We have a simple binary file format for caching data in our application (C# .NET Windows App). The format is basically a short that indicates the object type followed by a guid (string) for the object id then any object specific data (strings ints…
Steve Whitfield
  • 1,981
  • 3
  • 21
  • 30
2
votes
2 answers

Writing a text file into a gz file using GZipStream without first writing the text file to disk

Im currently generating a large output from a few database queries. The resulting XML file is about 2GB. (This is a years worth of data). To save some disk space and download time for the client i am adding this file into a compressed file using the…
CathalMF
  • 9,705
  • 6
  • 70
  • 106
2
votes
1 answer

DeflateStream / GZipStream to CryptoStream and vice versa

I want to to compress and encrypt a file in one go by using this simple code: public void compress(FileInfo fi, Byte[] pKey, Byte[] pIV) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { …
PePe
  • 65
  • 1
  • 6
2
votes
1 answer

gzip a stream and send it with WCF

I try to send a gzipped stream with WCF. Here the code server side : static void Main(string[] args) { var baseAddress = new Uri("http://localhost:2016/TransferServer"); var host = new ServiceHost(typeof(TransferServer),…
Bastiflew
  • 1,136
  • 3
  • 18
  • 31
2
votes
1 answer

Can I get a GZipStream for a file without writing to intermediate temporary storage?

Can I get a GZipStream for a file on disk without writing the entire compressed content to temporary storage? I'm currently using a temporary file on disk in order to avoid possible memory exhaustion using MemoryStream on very large files (this is…
Boinst
  • 3,365
  • 2
  • 38
  • 60
2
votes
2 answers

What would cause GZipStream compressed data to have excessive padding with zeroes?

I'm compressing some packets of data using the GZipStream class within the .NET framework. Everything works fine and the compression ratio is OK, but when I peek at the compressed data using a hex editor I noticed that as much as a third of each…
redcalx
  • 8,177
  • 4
  • 56
  • 105