This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HaddockDev's profile picture

Lempel Ziv Welch (LZW) Compression

Started by HaddockDev, 13 February 2017 - 05:32 PM
HaddockDev #1
Posted 13 February 2017 - 06:32 PM
LZW is a sorta not really kinda compression algorithm thingy created by Abraham Lempel, Jacob Ziv, and Terry Welch hence the name, Lempel Ziv Welch. It is used in the *nix program compress, and GIF images.

I have ported somebody's implementation of it in Lua, you can find the original here.

It isn't really that bad, but it has it's quirks. (Shaves 1 character off of "This is a test.", your mileage may vary.)
It is also fast, less than a second for "This is a test."

UsageBecause the original implementation was really simple, this inherits that.
Load up the API
os.loadAPI("/lzw")
,
and use lzw.Encode(text) and lzw.Decode(text) to inflate and deflate.

You can download it with: pastebin get WZKTR9q4 lzw
Yeah, I know about the typos. I originally thought it was LWZ.
Also, sorry about the sad mush of a post I made. Couldn't upload much because were dealing with a storm at the moment

The API is licensed under MIT because of the original file.
You can find a layman term page for MIT here.
Edited on 25 February 2017 - 10:55 AM
Bomb Bloke #2
Posted 14 February 2017 - 12:03 AM
Don't forget to follow the terms of the original license!

You might consider adding linebreak codes, such as \n and perhaps \r, to your dictionary. Tabs (\009) wouldn't hurt either.
HaddockDev #3
Posted 14 February 2017 - 02:43 PM
Don't forget to follow the terms of the original license!
There was none, so I just ported it. But, I still gave credit.

You might consider adding linebreak codes, such as \n and perhaps \r, to your dictionary. Tabs (\009) wouldn't hurt either.

Yeah, I could. I'll update it later.
KingofGamesYami #4
Posted 14 February 2017 - 03:44 PM
Read the first four lines of the file you linked.

Specifically,
This code is MIT licensed, see http://www.opensource.org/licenses/mit-license.php
(C) 2013 - Guava
Edited on 14 February 2017 - 02:45 PM
HaddockDev #5
Posted 25 February 2017 - 11:52 AM
Read the first four lines of the file you linked.

Specifically,
This code is MIT licensed, see http://www.opensourc...mit-license.php
© 2013 - Guava

Ah, my bad. I'll write a little notice now.