Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Compressing Genesis

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

Leave a Reply

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



En kopp kaffe!

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

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips