StringTools
Compress
compress a string or byte sequence
Calling Sequence
Parameters
Description
Examples
Compress(S)
Compress(S, n)
Compress(S, output=f)
S
-
string, Array(datatype=integer[1]), or list(integer)
n
(optional) positive integer number of bytes
f
(optional) output format, either rtable or list
The Compress(S) command takes the given string, byte list, or integer[1] array and compresses it into a lossless, more compact format.
By default the return value is an Array with datatype=integer[1]. The values in the array range from -128 to 127 as integer[1] is a signed integer format.
When output=list is specified the return value is a list of integers in the range 0 to 256.
Both the array output format and the list output format are suitable for use with readbytes and writebytes.
The optional value n indicates that only the first n bytes should be compressed. If n is unspecified, or if n <= 0 or if n exceeds the actual number of bytes, then all of S is compressed.
The compression algorithm is taken from the zlib library written by Jean-loup Gailly and Mark Adler. See http://zlib.net
Compress a string and retrieve it.
with⁡StringTools:
r≔Compress⁡hello world
r≔120−100−5372−51−55−558740−4947−5473970030104493
Uncompress⁡r,output=string
hello world
Compress the Thue-Morse word on 10^7 (ten million) letters by 99%.
tm≔ThueMorse⁡107:
compressed≔Compress⁡tm
1.−numelems⁡compressedlength⁡tm
0.9907413000
See Also
copyright
readbytes
rtable
Uncompress
writebytes
Download Help Document