Tuesday, December 7, 2010

NET System.IO.Compression and zip files

Today i observed an interesting thing in this name space I had a file of 713 kb
When i compressed this file it got a new side of 738KB and when I decompressed this file again it got 712 kb. interestingly file sized increased which I observed on many forum.

http://www.eggheadcafe.com/articles/20011231.asp
http://dotnetslackers.com/Microsoft/re-25702_NET_System_IO_Compression_and_zip_files.aspx
http://pluralsight.com/blogs/craig/archive/2004/03/19/1266.aspx
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=179704&SiteID=1
http://blogs.wdevs.com/marcclifton/archive/2005/11/22/11303.aspx


some lines from my code. i think i am too old to play with code now

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sf As System.IO.FileStream = New System.IO.FileStream("c:\test1.doc", FileMode.Open)

Dim ds As System.IO.FileStream = New System.IO.FileStream("C:\test2.doc", FileMode.CreateNew)

Dim Compressedfile As System.IO.Compression.GZipStream = New System.IO.Compression.GZipStream(sf, CompressionMode.Decompress)

'Dim byteData(sf.Length) As Byte

'sf.Read(byteData, 0, sf.Length)

'Compressedfile.Write(byteData, 0, byteData.Length)

'Dim destinationfile(Compressedfile.Length) As Byte

'Compressedfile.Read(destinationfile, 0, destinationfile.Length)

'Dim sw As StreamWriter = New StreamWriter(ds)

'sw.Write(destinationfile, 0, destinationfile.Length)

'ds.Write(destinationfile, 0, destinationfile.Length)

'ds.Close()

Dim data As Object

Do

data = CType(Compressedfile.ReadByte(), Integer)

If (CType(data, Integer) = -1) Then

Exit Do

End If

ds.WriteByte(CType(data, Byte))

Loop While (CType(data, Integer) <> -1)

End Sub

No comments: