Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deflate and inflate
#1
I've just stumbled across the _deflate and _inflate functions in QB64, and I reckon they may be quite useful.
But I don't think they've been given justice in the explanation of what they can do. Nothing there tells me what the resulting _deflated string will look like, or how it may be used (if it can) while deflated. Can they be treated like normal strings (concatenated, searched, used as a reference base etc.)? I can experiment, but I'm not up to improving the explanations. Hopefully someone can expand on things a bit?
Reply
#2
Take a file on your drive and deflate it... You now have a *.zip file 10% the size of the original. Of course, you can't do anything much with it while it's compressed, so you'll have to uncompress it before using it -- but it sure makes a heckuva difference when downloading and extracting a 10MB file, verses a 100MB one!

_Deflate compresses a string of data. (Think of it as turning your *.TXT file into a *.ZIP file.)

_Inflate reverses the process.
Reply
#3
Assuming that it is standard pkzip deflate, I think I may be right in saying that 7zip can't handle them (or was it implode?). All is not lost, however as the open source PeaZip can. FWIW, it can also extract other ancient archive formats such as Ace.

TR
Reply
#4
It's the zlib compression, which is used in PNG files and such. Wink
Reply
#5
The most used compression algorithm in the world is deflate, also known as zlib.
Deflate and zlib are basically the same algorithm but with a small important difference:
deflate RFC1951 is the pure compressed stream: no headers, just data
zlib RFC1950 is a deflate stream with a small header at the beginning and a CRC at the end
You can recognize it due to the presence of the 0x78 byte at the beginning of the compressed data
Just for the record, there is also the Gzip RFC1952 compression but it's mainly a container rather than a stream compression and it supports other algorithms, not only deflate.

Update:  Working link to zlib format file format specifications, in case anyone ever wants to actually create .zlib files and not just have the pure deflated data stream.  RFC 1950 ZLIB Compressed Data Format Specification version 3.3
Reply
#6
(05-19-2022, 11:46 AM)TarotRedhand Wrote: Assuming that it is standard pkzip deflate,
I think I may be right in saying that 7zip can't handle them (or was it implode?).
All is not lost, however as the open source PeaZip can.
FWIW, it can also extract other ancient archive formats such as Ace.

Interesting, thanks for this info. 

Perhaps it would be a worthwhile future enhancement to the QB64 inflate/deflate commands, to be able to choose the compression format (e.g. ZIP, 7ZIP, TAR, etc.)?
Reply
#7
I get it; So it's a zip function.
It will be useful for me at some time I think.
 Maybe I'm dense, but I still feel its explanation in the Help section needs "deflating", to clarify how to use it.
Reply
#8
(05-19-2022, 11:27 PM)PhilOfPerth Wrote: I get it; So it's a zip function.
It will be useful for me at some time I think.
 Maybe I'm dense, but I still feel its explanation in the Help section needs "deflating", to clarify how to use it.

Give a look over at the quick little topic I wrote up here on this, see if it helps you understand what's going on:  A quick lesson on _DEFLATE and _INFLATE (qb64phoenix.com)
Reply
#9
Got it, now I think. So, we don't use them while creating a prog, just to transmit or store it. Thanks Steve. Big Grin
Reply
#10
You can use it with your program to reduce memory usage, but usually you'd need to _INFLATE the compressed data before you can interact with it.

Think of writing a program to use to study the whole bible with. How many bytes of memory would you use to store the whole thing uncompressed? (350,000 or so, I think) But here's an idea -- what if you compress each chapter, and only uncompress the one the user is actually studying? How much memory would you save?

You compress things to reduce their size on disk, or in memory, but you need to uncompress them before you can make use of them. Wink
Reply




Users browsing this thread: 3 Guest(s)