Recent

Author Topic: LZ-String compress decompress  (Read 1842 times)

dkur

  • Newbie
  • Posts: 3
LZ-String compress decompress
« on: July 22, 2022, 09:31:07 am »
Hello,
I want to know, is there any LZ-String implementation in pascal/lazarus ?.
Just something like this : https://github.com/rufushuang/lz-string4java

Sorry for my bad english

Yours faithfully,
dkur

Handoko

  • Hero Member
  • *****
  • Posts: 5146
  • My goal: build my own game engine using Lazarus
Re: LZ-String compress decompress
« Reply #1 on: July 22, 2022, 10:03:50 am »
Hello dkur,
Welcome to the forum.

I inspected into the source code of ZBase.pas, the Lazarus/FPC component for handling compression. It does mention LZ77, see line #91 in the picture below:
« Last Edit: July 22, 2022, 10:08:21 am by Handoko »

dkur

  • Newbie
  • Posts: 3
Re: LZ-String compress decompress
« Reply #2 on: July 23, 2022, 08:14:02 am »
Hi, thanks for your reply.
I need LZ-String implementation for my laz coding. It seems that zbase not fit for my coding.
I need to decode json output from uricomponent method.

Thaddy

  • Hero Member
  • *****
  • Posts: 14352
  • Sensorship about opinions does not belong here.
Re: LZ-String compress decompress
« Reply #3 on: July 23, 2022, 09:20:45 am »
Which LZ do you need? LZO, LZ4, LZ77, LZ78, LZP, LZH,  LZ77, LZSS, LZMA, LZW and more? There are many flavors, but you simply state LZ.
Lempel-Ziff on its own is more of an academic excercise and hardly used on its own.
Lempel-Ziff-Hoffman is a practical implementation and so is e.g the Lempel-Ziff-Storer-Symanski.
The code you link to isn't too clear about what is implemented. Just that it can do lossless compress and decompress.
It misses any academic reference.
(I suspect you just need a deflate)
All these algorithms are rather simple to implement for an intermediate programmer, but without knowing the flavor I can not help you.
Maybe zlib will work and comes as standard package in the fpc distribution. It is also standards conformant.
It contains extensive documentation in the sourcecode (so you need the package sourcecode -: zlib.pas. It also works to decompress Python compressed sources and vice-versa, so that may be the right one.
« Last Edit: July 23, 2022, 09:59:56 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

dkur

  • Newbie
  • Posts: 3
Re: LZ-String compress decompress
« Reply #4 on: July 23, 2022, 03:18:48 pm »
Hi, thanks for you reply
Sory for my respon before, not decoded, what i mean or need is LZ-String code in pascal to decompress json file, the json file before, was encrypted by aes & sha256. LZ-string, i think its implementation of lzw algorithm.

In the link i mentioned before, it was lz string write in java. In github also there was go, vb net, c# code for lz string but none in pascal.


Sory for my bad english.

mazziqin

  • Newbie
  • Posts: 1
Re: LZ-String compress decompress
« Reply #5 on: November 19, 2023, 08:10:39 am »
Which LZ do you need? LZO, LZ4, LZ77, LZ78, LZP, LZH,  LZ77, LZSS, LZMA, LZW and more? There are many flavors, but you simply state LZ.

i think what dkur need is lz-string pieroxy https://pieroxy.net/blog/pages/lz-string/index.html

Hi, thanks for you reply
Sory for my respon before, not decoded, what i mean or need is LZ-String code in pascal to decompress json file, the json file before, was encrypted by aes & sha256. LZ-string, i think its implementation of lzw algorithm.

You can use Mormot SynCommons, SynCrypto to decrypt AES-256-CBC
« Last Edit: November 19, 2023, 08:15:39 am by mazziqin »

cdbc

  • Hero Member
  • *****
  • Posts: 1069
    • http://www.cdbc.dk
Re: LZ-String compress decompress
« Reply #6 on: November 19, 2023, 09:12:22 am »
Hi
DCPCrypt?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

lagprogramming

  • Sr. Member
  • ****
  • Posts: 405
Re: LZ-String compress decompress
« Reply #7 on: November 19, 2023, 02:17:34 pm »
compiler/cutils.pas contains an "Ultra basic KISS Lzw (de)compressor". You have to change string to shortstring in order to make sure it compiles because it contains inc(minilzw_*encode[0]), thus modifying the string length directly, without the setlength procedure. Obviously, the original code can be modified especially because "It's a pity that we still need those awfull tricks with this modern compiler. Without this performance of the entire procedure drops about 3 times.". Most likely, the comment regards the use of a label.

AlexTP

  • Hero Member
  • *****
  • Posts: 2398
    • UVviewsoft
Re: LZ-String compress decompress
« Reply #8 on: November 20, 2023, 12:01:00 pm »
@lagprogramming,
Is it the bugfix for FPC? How does it work yet w/o bugfix?

domasz

  • Sr. Member
  • ****
  • Posts: 433
Re: LZ-String compress decompress
« Reply #9 on: November 20, 2023, 01:31:03 pm »
This is a working LZW decompressor. Works fine with Unix compress .Z files:
https://github.com/PascalVault/Lazarus_Unpacker/blob/main/lzw.pas

 

TinyPortal © 2005-2018