Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2009-11-22
From here, I have downloaded Genesis to see what the GZip stream is good for. GZip is suitable for compressing text, because the file format is totally clean (uncompressed) and the Deflate algorithm manages therefore to compress text to a high ratio. And I like the simile that deflating Genesis leaves very little left. It sort of works with my naturalistic worldview.
The function, CompressText is unchanged, so I only show the Main subroutine.
Sub Main() 'Load genesis. Dim S As String Using Sr As New System.IO.StreamReader("genesis.txt", System.Text.Encoding.UTF8) S = Sr.ReadToEnd() Sr.Close() End Using Console.WriteLine("{0} characters, {1} bytes.", S.Length, S.Length * 2) 'Compress it, and display the result. Dim B() As Byte = CompressText(S) Console.WriteLine("Compressed to {0} bytes.", B.Length.ToString()) Console.WriteLine("Difference: {0}%", (((S.Length * 2) / B.Length) * 100).ToString("n0")) End Sub
In this case, the uncompressed version is 588% of the size of the compressed version.
Categories: Visual Basic 9
Tags: Streams
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
Leave a Reply