Lazarus

Programming => General => Topic started by: Thiago Chaves on September 19, 2020, 05:23:31 am

Title: Decompress base64 encoded zlib file
Post by: Thiago Chaves on September 19, 2020, 05:23:31 am
Hello. How do I decompress a base64 encoded zlib file?

Title: Re: How was this file recorded in the database?
Post by: Aidex on September 19, 2020, 06:44:34 am
The character sequence looks like Base64
Title: Re: How was this file recorded in the database?
Post by: Thaddy on September 19, 2020, 01:01:20 pm
The character sequence looks like Base64

I had already tried to decode using the website https://www.base64decode.org/ but I was not successful. I'll try again.
Do you have read access to the database's meta-data? It looks to me like base64 too, but the character encoding of the underlying data is of importance: is it ASCII, which codepage? Is it UTF8? etc.
Title: Re: Decompress base64 encoded zlib file
Post by: Thiago Chaves on September 25, 2020, 02:43:15 pm
How do I decompress a base64 encoded zlib file using Lazarus?
Title: Re: Decompress base64 encoded zlib file
Post by: rvk on September 25, 2020, 03:07:00 pm
How do I decompress a base64 encoded zlib file using Lazarus?
After you decode the base64 (you can use DecodeBase64 in synacode.pas) you can use TGZFileStream to uncompress the stream.

Also see https://forum.lazarus.freepascal.org/index.php?topic=17520.0
Another more complete example https://forum.lazarus.freepascal.org/index.php/topic,50596.msg369612.html#msg369612
Title: Re: How was this file recorded in the database?
Post by: lucamar on September 25, 2020, 06:19:35 pm
Do you have read access to the database's meta-data? It looks to me like base64 too, but the character encoding of the underlying data is of importance: is it ASCII, which codepage? Is it UTF8? etc.

Thaddy, if it is base64 then by definition the data must be plain ASCII, isn't it? After all, that's the conventional use of that type of codification, to transfer across channels where one can't be sure 8 bits/char would survive intact.

Another thing would be the "codepage", if any, of the decoded result but since in this case (as in most where base64 and similar codings are used) the result is a binary object, it shouldn't matter.
Title: Re: How was this file recorded in the database?
Post by: Thaddy on September 25, 2020, 08:22:26 pm
Thaddy, if it is base64 then by definition the data must be plain ASCII, isn't it?
No. it can also be rawbytestring or even array of bytes.
Base64 is BYTE oriented, not CHAR (Pascal) oriented.Maybe you mix up C char with Pascal byte?
 But I assume you know all that?  O:-)

Basically Base64 is content agnostic. It can encode/decode anything that can be represented as a series of bytes.
 See https://en.wikipedia.org/wiki/Base64
Only the encoded result is ASCII. Not the data, nor the decryption of the original data.
Title: Re: Decompress base64 encoded zlib file
Post by: Thiago Chaves on September 25, 2020, 09:01:43 pm
I solved. I used the ACBr components, which many people use here in Brazil. With a simple command line:

Uses
  ACBrUtil, synacode;
 
...

StrFinal := UnZip(DecodeBase64(Base64Str));
TinyPortal © 2005-2018