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
3 answers

Gzipstream header and suffix

How do I know the size of my compressed file used GzipStream? I know that it has a header and suffix. First 10 bytes - it's header, second 8 bytes - suffix. How do I know the size file in the suffix?
Alex
  • 63
  • 1
  • 10
1
vote
1 answer

Why the length of zipped stream is always 10?

I am testing some code. I am stuck with the following. What ever I write as text, the length of the zipped stream is always 10? What am I doing wrong? var inStream = new MemoryStream(); var inWriter = new StreamWriter(inStream); str text =…
Nuri Tasdemir
  • 9,720
  • 3
  • 42
  • 67
1
vote
0 answers

C# WebRequest download as Gzip, but don't decompress

How can I tell WebRequest to not decompress the gzipped response ? The response does not need to be decompressed because it will be passed along to another function that expects a Gzipped stream. As far as I can tell, setting the…
user5133888
  • 139
  • 1
  • 11
1
vote
0 answers

Method that return a string with an specifc extension

Im a long time trying to solve one problem. I have one method that Serialize a string, follows the code: XmlRetorno() var algumasDef = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }; …
Edi
  • 615
  • 5
  • 15
1
vote
2 answers

GZipStream quietly fails on large file, stream ends at 2GB

I'm having trouble using GZipStream to decompress the FreebaseRDF dump (30GB gzipped text, 480GB uncompressed) where the stream ends prematurely. No exception is thrown, just gz.Read() starts returning zero: using(var gz = new…
gordy
  • 9,360
  • 1
  • 31
  • 43
1
vote
1 answer

PowerShell Decompress GZip Pipe using lots of memory

I'm writing a powershell Cmdlet to accept a list of files references to gzipped files and to decompress them and put their text lines on the pipeline. I have something functioning, but it's using tons of memory. What's interesting is that after is…
markdemich
  • 301
  • 2
  • 13
1
vote
2 answers

Which kind of commpression do I have to use? Or use StreamContent with JsonTextWriter

I'm developing an ASP.NET Web Api 2.2 application with .NET Framework 4.5, C# and Newtonsoft.Json 6.0.8. I have this method to post to this web api: protected bool Post(string completeUri, ref T dataToPost) { bool result = false; using…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
1
vote
2 answers

Unable to access GZipStrean due to protection level

I just want to access System.IO.Compression.GZipStream class to decompress Web Http response. But I am unable to access GZipStream class due to protection level. I am using Mvvm cross for mobile development. Here is GZipStream class code…
Uddhao Pachrne
  • 531
  • 1
  • 8
  • 22
1
vote
0 answers

Error: Not in GZIP format - attempt to decompress GZIP stream previously stored in a database field

Streaming confuses me - just when I think I'm grasping the idea, my code goes belly up. I'm attempting to take in a string, gzip compress it, and store it in a PostGreSQL database. THEN I want to get it back out and re-transform it into an output…
1
vote
1 answer

C# GZipStream compression not writing to file

I have this simple example (copied from the MSDN documentation), but the .gz file get never created... I have tried to add a call to compressedFileStream.Flush(); but nothing... static string directoryPath = @"C:\\temp\\"; ... public string…
spiderman
  • 1,565
  • 2
  • 16
  • 37
1
vote
0 answers

GZip .NET Compact Framework 3.5

I am trying to send and receive process gzip-ed data from server on my client device application (not web). I am sending gzip-ed content and on client side, I have following method that returns WebResponse: protected override WebResponse…
pixel
  • 9,653
  • 16
  • 82
  • 149
1
vote
3 answers

Is GZipStream header reliable across .NET versions?

I came to the Q&A Is there a way to know if the byte[] has been compressed by gzipstream? and some author states (and it's true) that GZipStream puts {0x1f, 0x8b, 8, 0, 0, 0, 0, 0, 4, 0} characters as header to know if a byte array is a compressed…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
1
vote
2 answers

how to both Compress and Minify content together?

i know we can compress response by declaring Response.Filter as GZip or Delfalte streams, but how i can perform both compression and minification together? declaring new class that inherits Stream, then first performing minify on content, then…
Sadegh
  • 4,181
  • 9
  • 45
  • 78
1
vote
1 answer

Do I need to have a checksum if I am using GZIP?

I am using GZIP compression to send a payload via sockets. Should I also send a md5 checksum with that or does GZIP handle the checksum for me and my checksum would just add unneeded size?
TomShar
  • 129
  • 1
  • 2
  • 12
1
vote
1 answer

FTP + GZipStream = 'File is broken' when unzipped

I am trying to use a GZipStream to compress a document prior to uploading to an FTP server. If I save the compressed file stream to disk just prior to uploading, the copy on the local file system is correct. However, when I try to unzip the file on…
Derpy
  • 1,458
  • 11
  • 15