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
0
votes
2 answers

How to convert GZipStream to HttpContent?

I have written a Web API code to return a zip file. But I am not able to convert the GZipStream content to HttpContent. I get the following error: cannot implicitly convert type 'system.io.compression.GZipStream' to …
Md Aslam
  • 1,228
  • 8
  • 27
  • 61
0
votes
0 answers

Problems with decompressing GZipStream

public void CompressFile(string fileName, string outFile) { var sync = new object(); using (var inStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (var bReader = new…
0
votes
0 answers

GZip Compression - Sending PDF Stream in Response.OutputStream

I have a website deployed in IIS, where user can view PDF files on browser (using embedded html object) or download large PDF files. Currently on server side, I am sending PDFStream in Response.OutputStream.Write. I want to improve performance by…
0
votes
1 answer

Compression/Decompression for DataSet or any .Net Object

I'm developing a WPF App, in which I want to encrypt and compress heavy DataSet or Objects (<2MB) and send it across over the network. The other party would decompress and decrypt the data and consume it. This process will be on both sides from…
Varun Jain
  • 1,015
  • 2
  • 13
  • 19
0
votes
1 answer

Failed to use GZipStream to decompress a file (without using CopyToAsync)

I'm trying to to decompress a MemoryStream using ReadAsync/WriteAsync but it's not working. int bufferSize = 8192; using (var memoryStream = new MemoryStream()) using (var fileStream = new FileStream(destinationFilename, FileMode.Create,…
pellea
  • 359
  • 3
  • 21
0
votes
2 answers

EndOfStreamException: Failed to Read past end of stream (Unity 3d)

i'm trying to decompress a file in memory using GZipStream, copy the decompressed data to a MemoryStream, and then read the MemoryStream using BinaryReader (from Unity 3d). However, i get these errors when i try to run it: EndOfStreamException:…
0
votes
0 answers

How to stop GzipStream blocking in Dispose?

I am reading from a GzipStream which wraps a NetworkStream in a UI event handler. using (var gzipStream = new GzipStream(networkStream, CompressionMode.Decompress) { await WriteSomethingToStream(gzipStream); } The DeflateStream which the…
wingerse
  • 3,670
  • 1
  • 29
  • 61
0
votes
1 answer

How to receive a GZIP post request in a Web API?

I am trying to receive a post from a data provider using a Web API. When I save the request from my web api with the function below: public async Task Import(HttpRequestMessage request) and then save the stream from the code…
Fredrik
  • 290
  • 1
  • 8
0
votes
1 answer

C# - Arithmetic overflow - Decompression of string via gzipstream

I'm having an issue with implementing a GZIP string decompressor. The compressed string is a20d32fdda14b300b28aa6b72982af3b as shown below. However, when running this code, I receive the error: "System.OverflowException occurred …
Kavinda JD
  • 23
  • 4
0
votes
0 answers

GZipStream read bytes uncompressed

Does anyone know how I can get the compressed contents of a GzipStream? I just want to read all bytes without decompressing so I can get the length and forward onto a web request with the content-length. The source of the file is from RavenFS which…
Lenny D
  • 1,734
  • 4
  • 22
  • 43
0
votes
1 answer

How can i find the start of Gzip string in a MemoryStream?

byte[] httpDecompress(HttpDatagram http) { int magicnum = 0x1f8b; Stream str= http.Body.ToMemoryStream(); using (var zipStream = new GZipStream(str, CompressionMode.Decompress)) using (var resultStream = new…
0
votes
1 answer

TCP HTTP Gzip String Decompression C#

I'm working on a project about packet listening. I got a problem with gzip decompression. There is the code: private static string gzipDecompress(TcpDatagram tcp) { if (tcp.Http.Header != null) { MemoryStream ms =…
0
votes
0 answers

Async HttpWebRequest + AutomaticDecompression Stack Overflow Exception

I am troubleshooting a legacy web service (asmx) that works to verify prices on partner websites. We have recently turned on the HttpWebRequest.AutomaticDecompression flag (DecompressionMethods.Deflate | DecompressionMethods.GZip) to hopefully…
Kris Oye
  • 1,158
  • 14
  • 27
0
votes
0 answers

How to get all files from archive file in c#?

I have read email attachment and if archive file then find out how many files are there into archive file. and any exe using programmatically without store any temporary location. I have find out getting attachment content as string or byte. from…
tthewolf3D
  • 330
  • 1
  • 2
  • 13
0
votes
0 answers

Firebase storage decompresses my file when uploading

i have a wierd problem i cant seem to get around. I have a gzip file that i can upload to my Firebase Storage bucket easily using the gsutil tool: gsutil -h "Content-Encoding:gzip" -h "Content-Type:application/json" cp…
Swift
  • 166
  • 2
  • 16