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

Decompress gzip file that contine multiple blocks

I have a Gzip file that has multiple blocks.Every block starts with 1F 8B 08 And ends with 00 00 FF FF I tried to decompress the file using 7-Zip and gzip tool in linux ,But I always get an error saying that the file is invalid. So I wrote…
Minato
  • 75
  • 2
  • 7
0
votes
0 answers

How to write gzipped content to an HDFS file in iterations?

I am able to write gzipped compressed data to an HDFS file. But what if I have to write this data in iterations. So, for example, in one iteration, I compress a string using the GZIPOutputStream library, and write that compressed string to the HDFS…
pythonic
  • 20,589
  • 43
  • 136
  • 219
0
votes
1 answer

Disposing MemoryStreams and GZipStreams

I want to compress a ProtoBuffer object on serialisation and decompress on deserialisation. Unfortunatly, C# stdlib offers only compression routines that work on streams rather than on byte[], that makes it a bit unesseray more verbose than a…
Michael K.
  • 423
  • 1
  • 4
  • 13
0
votes
1 answer

Ionic.zip Gzipstream Decompress ,Bad state (invalid stored block lengths)

i use ionic.zip gzipstream compress and decompress byte[], it can compress well,but when it decompressed from byte[] compressed it told Bad state (invalid stored block lengths) my codes bellow Trace.WriteLine(s.Length); var b =…
goldii
  • 242
  • 2
  • 18
0
votes
0 answers

Multithreading compress\decompress with use GzipStream

I read compressed data one block at a time and add these blocks to the queue. Then when I try to decompress that data using GzipStream InvalidDataException is shown stating that the magic number in the GzipHeader is incorrect. What header should my…
Alex
  • 63
  • 1
  • 10
0
votes
1 answer

GZipStream does not call underlying streams *Async methods when destination of CopyToAsync

Using the following construct for a GZipStream it never seems to call the *Async method of my custom stream when GZipStream is the destination of CopyToAsync. using (var fs = new…
Terry
  • 2,148
  • 2
  • 32
  • 53
0
votes
2 answers

downloading large amount of files

I'm researching solutions for a potential client. They're requesting the ability to download a large amount of MP3's (1000+) from their online catalog. I've researched/tested building a zip containing all MP3s using ZipArchive but ran into obvious…
Stephen S.
  • 837
  • 7
  • 16
  • 29
0
votes
2 answers

gzipstream decompress UNIX-File aborts with no error

My decompressing worked fine for years! But now I have some files that abort while decompressing after a few reads. The decompression will abort after 694 records but there are 1'829'768 records! I do not receive any error from the GZipStream. I am…
0
votes
1 answer

C# reuse GZipStream for more than one decompressions

I need to compress and decompress millions of strings individually. The first loop works. The second doesn't. Basically I don't know how to use streams. How do I get the second method, the one that reuses streams, to work? using System; using…
johnnycrash
  • 5,184
  • 5
  • 34
  • 58
0
votes
1 answer

How to convert a compressed stream to an uncompressed stream in c# using GZipStream

Following various samples I've been able to convert a memory stream to a compressed stream and then to a byte array to save in a database but I'm having trouble going the other way. Here's what I've got so far... ... using (MemoryStream…
nuander
  • 1,319
  • 1
  • 19
  • 33
0
votes
2 answers

Archiving a group of gzipped files

I have a group of about 10 gzipped files that I would like to archive into a single file in order for a user to download. I am wondering what the best approach to this would be. Gunzip everything, then tar-gz the complete set of files into a…
Brett
  • 11,637
  • 34
  • 127
  • 213
0
votes
0 answers

GZipStream Decompress not unzipping complete file

I am trying to unzip .gz files using GZipStream. It will only exctract 12kb of the file but if I use winzip or 7zip to unzip the .gz file the extracted file should be 753kb. See the code below that I am using, any pointers on where I am going wrong?…
Pauline
  • 19
  • 1
  • 2
0
votes
1 answer

How to make different names of file and archive in GZipStream compression?

I have a file in a current directory, which name is firstName. I want to create an archive with this file (name of file have to stay). The archive name have to be an archiveName. But when I use my code I get an archive with the rigth name but the…
Beras Mark
  • 53
  • 1
  • 9
0
votes
2 answers

C# SslStream with GZipStream

Is it possible to use GZipStream passing an SslStream in C#? i.e. can you do GZipStream stream = new GZipStream(sslStream, CompressionMode.Compress); stream.Write(...); ... GZipStream stream = new GZipStream(sslStream,…
Chris Cooper
  • 869
  • 2
  • 18
  • 42
0
votes
0 answers

jersey with GZipEncoder deploy error on WildFly

I have a simple jersey restful service which works fine. I have just added a GZipEncoder and after that I am not able to deploy my war on WildFly 10/9.0.2. An exception is throwed during deploy. I think a dependency is missing but the throwed…
zappee
  • 20,148
  • 14
  • 73
  • 129