Compressing Genesis

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.

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll:

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Comments

Important information: If you have not commented before, your comment will be reviewed before it is published. This means that you will not see it immediately, but I have received it. This is not because I want to filter comments, but because I want to prevent spam and advertising.

Leave a Reply

Your email address will not be published. Required fields are marked *