GZipStream compressed file is larger than source file

  • Thread starter Thread starter prince.matt
  • Start date Start date
P

prince.matt

Hi,

I am using GZipStream to compress a simple text file approx 24MB in
size. I am finding that the destination "compressed" file is several
MB larger than the source file (31MB). The code is as follows:

Dim sourcefile As FileStream = File.OpenRead(inFileName)
Dim destFile As FileStream = File.Open(outFilename,
FileMode.Create, FileAccess.Write)

Dim compStream As New GZipStream(destFile,
CompressionMode.Compress)

Dim myByte As Integer = sourcefile.ReadByte()
While myByte <> -1
compStream.WriteByte(CType(myByte, Byte))
myByte = sourcefile.ReadByte()
End While

Any ideas why the compressed file actually ends up larger than the
source?

Thanks,

Matt
 
Note, I have experienced the same result when using other files types,
eg: pdf and doc. I even tried using a DeflateStream instead of
GzipStream, and still the destination files are consistently larger
than the source files...
 
Back
Top