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

Download files as stream without downloading complete files into memory

I want to download files as stream from a remote server and make them zip stream and return it to frontend as stream without waiting all files to complete downloads. Is it possible in python and framework of python ?? I tried as below but its not…
Raheela Aslam
  • 452
  • 2
  • 13
1
vote
1 answer

C# GZipStream cannot use the CopyTo method when decompressed via MemoryStream

// code href="https://www.cnblogs.com/mahuanpeng/p/6851793.html" // Compress bytes //1. Create a compressed data stream //2. Set compressStream to store the compressed file stream and set it to compression mode //3. Write the bytes to be compressed…
1
vote
0 answers

GZipStream to ZipArchive

I'm working on a project where I want to obtain the file from a compressed archive which only holds a single file. The files I'm interested in opening are of the file extension .als (Ableton Live Set) and from 7Zip I've found they use the gzip…
BRHSM
  • 854
  • 3
  • 13
  • 48
1
vote
0 answers

VB.NET Decompress String using GZipStream

I'm trying to compress a string, store it in a variable, and then decompress it (using GZipStream), but nothing I try seems to work and everything I'm browsing doesn't help. The string is compressed properly, but then I just can't decompress it…
LPCarlos
  • 15
  • 3
1
vote
1 answer

Web Server "Content-Type" not configuring correctly on Apache

Extremely new to web servers: I'm trying to configure my web server to serve WebAssemblies (Edit: .wasm) as aplication/wasm I'm on a Hostinger host which uses an Apache as I understand. I'm also using gzip (Edit #3 The webpage is a Unity 'WebGL'…
David
  • 307
  • 3
  • 17
1
vote
2 answers

Why does my GZip implementation result in invalid gzip

I am attempting to gzip compress some data which is to be consumed by a separate app (a tilemap program called Tiled). I am unable to produce data which the app understands, and I believe it is because my zipped data is invalid. To verify, I have…
Victor Chelaru
  • 4,491
  • 3
  • 35
  • 49
1
vote
1 answer

GZipStream 4G limit - total or currently streaming?

Have aa GzipStream feeding an SSLStream. First time today noticed "The gzip stream can't contain more than 4GB data." at System.IO.Compression.FastEncoder.GetCompressedOutput(Byte[] outputBuffer) at…
Greg Domjan
  • 13,943
  • 6
  • 43
  • 59
1
vote
1 answer

Compress the response of service stack

I tried to compress the response of service stack using global filters but it not work throws 500 err code. here are my code this.GlobalResponseFilters.Add((req, response, requestDto) => { …
1
vote
2 answers

How do you compress a stream and upload it to Azure Blob Storage without writing to a file?

I have written a Post method in ASP.NET Core to compress the requests body and upload it to Azure Blob Storage. The method takes parameters as follows: public async Task Post([FromHeader] string AssignmentId) Various strings are then…
1
vote
3 answers

GZip Decompression Gives Blank File

Given the code below, why is the decompression not working? "NewFile2.txt" should have the original, decompressed text, but the file is just blank. ioTests.CompressFile(@"c:\newfile.txt",…
richard
  • 12,263
  • 23
  • 95
  • 151
1
vote
1 answer

Read AWS S3 GZIP Object using GetObjectRequest with range

I am trying to read a big AWS S3 Compressed Object(gz).I don't want to read the whole object, want to read it in parts,so that i can process the uncompressed data in parallel I am reading it with GetObjectRequest with "Range" Header, where i am…
Maverick
  • 626
  • 6
  • 11
1
vote
1 answer

C# Cannot access a closed stream while copying GZipStream to MemoryStream

I've been trying to convert a GZipStream into a MemoryStream and then convert it to a byte array without having to write any files to the hard drive. I've been trying to copy it to a MemoryStream but I've been getting this error: Unhandled…
salt
  • 83
  • 1
  • 8
1
vote
0 answers

how to correctly "pipeline" binary data to encryption (cipher) compress and write in a file ? using pure Node.js

I want to encrypt data read from file which is sent using cipheriv and then compress using gzipstrem and write in a file stream. but when I try to do this I am getting some error stream.on is not a function at destroyer…
1
vote
1 answer

How to decompress a GZip Compressed String in C#?

Have been currently trying to decompress a GZip-compressed string where I am using this function: private static string Decompress(byte[] bytes) { using (var memoryStream = new MemoryStream(bytes)) using (var gZipStream = new…
1
vote
1 answer

Problem with decompress, GZipStream

I have problem with decomress gzip: string fileData = string.Empty; // byte[] starts with 31 and 139 var gzBuffer = entity.Data.Skip(pos).ToArray(); using (GZipStream stream = new GZipStream(new…
user348173
  • 8,818
  • 18
  • 66
  • 102