Zimpel (Encoding / Decoding of files)

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Zimpel (Encoding / Decoding of files)

Post by rmcode »

A small module able to encode and decode files based on the classic LZ78 algorithm.

Instructions

Zimpel can encode and decode strings:

Code: Select all

local Zimpel = require('Zimpel')

local code = Zimpel.encode( "I have come here to chew bubblegum and kick ass...and I'm all out of bubblegum." )
print( code )

local msg = Zimpel.decode( code );
print( msg )
There are also functions for encoding and decoding tables:

Code: Select all

local Zimpel = require('Zimpel')

local example = {
    bubblegum = false,
    kickass = true,
    equipment = {
        "sunglasses",
        "shotgun"
    }
}

local code = Zimpel.encodeTable( example )
print( code )

local dtable = Zimpel.decodeTable( code );
for i, v in pairs( dtable ) do
    print( i, v )
end
Example output for ("Hello World. How are you?"):

Code: Select all

 0H   0e   0l   3o   0    0W   0o   0r   3d   0.   5H   7w   5a   8e   5y   7u   0?
I wrote it for fun, but I thought it might be useful for some people. Could be used to encode save games so they can't be edited (easily).

The code lives on github.
Last edited by rmcode on Wed Jan 20, 2016 6:18 pm, edited 1 time in total.
User avatar
Jack5500
Party member
Posts: 148
Joined: Wed Dec 07, 2011 8:38 pm
Location: Hamburg, Germany

Re: Zimpel (Encoding / Decoding of files)

Post by Jack5500 »

So this is basicly serialisation. Can is serialise/encode userdata as well? What about Images?
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Zimpel (Encoding / Decoding of files)

Post by rmcode »

Jack5500 wrote:Can is serialise/encode userdata as well? What about Images?
Only if you turn them into a string :P
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Zimpel (Encoding / Decoding of files)

Post by zorg »

One could combine the resulting serialized strings from robin's ser/lady/smallfolk with this as well, really useful! :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Frohman
Prole
Posts: 21
Joined: Sat Dec 08, 2012 12:32 pm

Re: Zimpel (Encoding / Decoding of files)

Post by Frohman »

Not to detract from this, but can't you use love's (now built in) compression wrapper functions to achieve the same thing, faster?
See; https://love2d.org/wiki/love.math.compress and https://love2d.org/wiki/love.math.decompress

Nice work, though!
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Zimpel (Encoding / Decoding of files)

Post by rmcode »

Frohman wrote:Not to detract from this, but can't you use love's (now built in) compression wrapper functions to achieve the same thing, faster?
Most certainly!
Nice work, though!
Thanks - it was fun to write :)
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Zimpel (Encoding / Decoding of files)

Post by zorg »

Frohman wrote:Not to detract from this, but can't you use love's (now built in) compression wrapper functions to achieve the same thing, faster?
Sure, but love can only use lz4 and DEFLATE algorithms (the latter in two "flavours"), and this one is an LZ78 implementation, so totally different! :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Zimpel (Encoding / Decoding of files)

Post by rmcode »

zorg wrote:Sure, but love can only use lz4 and DEFLATE algorithms (the latter in two "flavours"), and this one is an LZ78 implementation, so totally different! :3
DEFLATE is based on LZ77 (IIRC) and then encoded via Huffman. Would be totally futile (= fun) to try writing that one in Lua too :D
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Zimpel (Encoding / Decoding of files)

Post by rmcode »

Small bugfix release:

Code: Select all

# Version 1.0.1 ( 2016-01-20 )
- Fixed encoding of tables containing strings with apostrophes
- Fixed encoding of tables containing sequences
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests