DEFLATE$: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary Tag: Manual revert |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
{{PageSyntax}} | {{PageSyntax}} | ||
:{{Parameter|result$}} = [[_DEFLATE$]]({{Parameter|stringToCompress$}}) | :{{Parameter|result$}} = [[_DEFLATE$]]({{Parameter|stringToCompress$}}[, {{Parameter|compressionLevel&}}]) | ||
{{PageDescription}} | {{PageDescription}} | ||
* {{Parameter|result$}} will contain the compressed version of {{Parameter|stringToCompress$}}. | * {{Parameter|result$}} will contain the compressed version of {{Parameter|stringToCompress$}}. | ||
* {{Parameter|compressionLevel&}} is an optional compression level (0 - 10), where 10 is the highest level and 0 is no compression. | |||
* To decompress the resulting string, use [[_INFLATE$]]. | * To decompress the resulting string, use [[_INFLATE$]]. | ||
== | {{PageAvailability}} | ||
* ''' | <!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no --> | ||
<gallery widths="48px" heights="48px" mode="nolines"> | |||
File:Qb64.png|'''v1.4''' | |||
File:Qbpe.png|'''all''' | |||
File:Apix.png | |||
File:Win.png|'''yes''' | |||
File:Lnx.png|'''yes''' | |||
File:Osx.png|'''yes''' | |||
</gallery> | |||
<!-- additional availability notes go below here --> | |||
* Compression level support was added in '''QB64-PE v4.1.0'''. | |||
Line 19: | Line 30: | ||
''Example 1:'' Compressing a long string of text. | ''Example 1:'' Compressing a long string of text. | ||
{{CodeStart}} | {{CodeStart}} | ||
a$ = "The quick brown fox jumps over the lazy dog. " | a$ = {{Text|<nowiki>"The quick brown fox jumps over the lazy dog. "</nowiki>|#FFB100}} | ||
{{Cl|PRINT}} "Original string (a$): "; a$ | {{Cl|PRINT}} {{Text|<nowiki>"Original string (a$): "</nowiki>|#FFB100}}; a$ | ||
{{Cl|FOR}} i = 1 {{Cl|TO}} 15 | {{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|15|#F580B1}} | ||
a$ = a$ + a$ | a$ = a$ + a$ | ||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{Cl|PRINT}} "After concatenating it into itself several times, LEN(a$) ="; {{Cl|LEN}}(a$) | {{Cl|PRINT}} {{Text|<nowiki>"After concatenating it into itself several times, LEN(a$) ="</nowiki>|#FFB100}}; {{Cl|LEN}}(a$) | ||
b$ = {{Cl|_DEFLATE$}}(a$) | b$ = {{Cl|_DEFLATE$}}(a$) | ||
{{Cl|PRINT}} "After using _DEFLATE$ to compress it, LEN ="; {{Cl|LEN}}(b$) | {{Cl|PRINT}} {{Text|<nowiki>"After using _DEFLATE$ to compress it, LEN ="</nowiki>|#FFB100}}; {{Cl|LEN}}(b$) | ||
{{Cl|PRINT USING}} "(compressed size is #.###% of the original)"; (({{Cl|LEN}}(b$) * 100) / {{Cl|LEN}}(a$)) | {{Cl|PRINT USING}} {{Text|<nowiki>"(compressed size is #.###% of the original)"</nowiki>|#FFB100}}; (({{Cl|LEN}}(b$) * {{Text|100|#F580B1}}) / {{Cl|LEN}}(a$)) | ||
c$ = {{Cl|_INFLATE$}}(b$) | c$ = {{Cl|_INFLATE$}}(b$) | ||
PRINT "After using _INFLATE$ to decompress it, LEN ="; {{Cl|LEN}}(c$) | {{Cl|PRINT}} {{Text|<nowiki>"After using _INFLATE$ to decompress it, LEN ="</nowiki>|#FFB100}}; {{Cl|LEN}}(c$) | ||
{{CodeEnd}} | |||
{{OutputStart}} | {{OutputStart}} | ||
Original string (a$): The quick brown fox jumps over the lazy dog | Original string (a$): The quick brown fox jumps over the lazy dog | ||
Line 44: | Line 55: | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[_INFLATE$]] | * [[_INFLATE$]] | ||
* [[_BASE64DECODE$]], [[_BASE64ENCODE$]] | |||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 18:46, 30 January 2025
The _DEFLATE$ function compresses a string.
Syntax
- result$ = _DEFLATE$(stringToCompress$[, compressionLevel&])
Description
- result$ will contain the compressed version of stringToCompress$.
- compressionLevel& is an optional compression level (0 - 10), where 10 is the highest level and 0 is no compression.
- To decompress the resulting string, use _INFLATE$.
Availability
- Compression level support was added in QB64-PE v4.1.0.
Examples
Example 1: Compressing a long string of text.
a$ = "The quick brown fox jumps over the lazy dog. " PRINT "Original string (a$): "; a$ FOR i = 1 TO 15 a$ = a$ + a$ NEXT PRINT "After concatenating it into itself several times, LEN(a$) ="; LEN(a$) b$ = _DEFLATE$(a$) PRINT "After using _DEFLATE$ to compress it, LEN ="; LEN(b$) PRINT USING "(compressed size is #.###% of the original)"; ((LEN(b$) * 100) / LEN(a$)) c$ = _INFLATE$(b$) PRINT "After using _INFLATE$ to decompress it, LEN ="; LEN(c$) |
Original string (a$): The quick brown fox jumps over the lazy dog After concatenating it into itself several times, LEN(a$) = 1474560 After using _DEFLATE$ to compress it, LEN = 4335 (compressed size is 0.295% of the original) After using _INFLATE$ to decompress it, LEN = 1474560 |
See also