Recent

Author Topic: Decompress base64 encoded zlib file  (Read 774 times)

Thiago Chaves

  • Newbie
  • Posts: 3
Decompress base64 encoded zlib file
« on: September 19, 2020, 05:23:31 am »
Hello. How do I decompress a base64 encoded zlib file?

« Last Edit: September 25, 2020, 02:38:47 pm by Thiago Chaves »

Aidex

  • Jr. Member
  • **
  • Posts: 66
Re: How was this file recorded in the database?
« Reply #1 on: September 19, 2020, 06:44:34 am »
The character sequence looks like Base64

Thaddy

  • Hero Member
  • *****
  • Posts: 10572
Re: How was this file recorded in the database?
« Reply #2 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.

Thiago Chaves

  • Newbie
  • Posts: 3
Re: Decompress base64 encoded zlib file
« Reply #3 on: September 25, 2020, 02:43:15 pm »
How do I decompress a base64 encoded zlib file using Lazarus?

rvk

  • Hero Member
  • *****
  • Posts: 4386
Re: Decompress base64 encoded zlib file
« Reply #4 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
« Last Edit: September 25, 2020, 03:12:57 pm by rvk »

lucamar

  • Hero Member
  • *****
  • Posts: 3188
Re: How was this file recorded in the database?
« Reply #5 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 10572
Re: How was this file recorded in the database?
« Reply #6 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.
« Last Edit: September 25, 2020, 08:40:23 pm by Thaddy »

Thiago Chaves

  • Newbie
  • Posts: 3
Re: Decompress base64 encoded zlib file
« Reply #7 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