vb.net - File Compressed by GZIP grows instead of shrinking -


I used the code below to compress the files and they continue to grow instead of shrinking. Forced the KB file and it became 6 This can be understood due to the compression overhead for a short file. I tried a 400 MB file and it became 628 MB after compressing. what is wrong? View code (.net 2.0)

  Public sub compression (Byval infile as string, by-out file as string) Dim source file as file stream = file. OpenRed (Infile) Dim destFile like FileStream = File.Create (outfile)) New GZipStream (destFile, CompressionMode.Compress) as a slow compost in the form of MyByte = sourceFile.ReadByte () while myByte & lt; & Gt; -1 compStream.WriteByte (CType (myByte, byte) myByte = sourceFile.ReadByte () End while sourceFile.Close () destFile.Close () end sub  

< Div class = "post-text" itemprop = "text">

Are you sure that writing byte byte in the stream is really a good idea? This will definitely not be the ideal performance feature, and perhaps it is that the GEZAP also confuses compressing algorithms.

In addition, it may be that the data you are trying to compress is actually not exactly correct, if I were you, then I would like to code your code with the same size text document Try to experiment because text documents process better than random binary.

In addition, you use a pure DeflateStream using a GZipStream because they both use the same compression algorithm (deflate), the only difference is that gzip adds some extra data (such as error checking ) So that a DeflateStream can produce small results.

My VB.NET is a bit cast, so I will not try to write a code example in VB.NET. Instead, you should do this in C #, VB for any experience. To translate on the Net, it should be relatively simple: (Or maybe someone who is good at VB.NET, can edit my post and translate it to VB.NET)

  file Stream source file; GZipStream compStream; Byte [] buffer = new byte [65536]; Int BitesRad = 0; While (bytes read = sourcefile.read (buffer, 0, 65536)> 0) {compStream.Write (buffer, 0, bytes read); }  

Comments