Compress - Maple Help

Online Help

All Products    Maple    MapleSim


StringTools

  

Compress

  

compress a string or byte sequence

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Compress(S)

Compress(S, n)

Compress(S, output=f)

Parameters

S

-

string, Array(datatype=integer[1]), or list(integer)

n

-

(optional) positive integer number of bytes

f

-

(optional) output format, either rtable or list

Description

• 

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

Examples

Compress a string and retrieve it.

withStringTools&colon;

rCompresshello world

r120−100−5372−51−55−558740−4947−5473970030104493

(1)

Uncompressr&comma;output=string

hello world

(2)

rCompresshello world

r120−100−5372−51−55−558740−4947−5473970030104493

(3)

Uncompressr&comma;output=string

hello world

(4)

Compress the Thue-Morse word on 10^7 (ten million) letters by 99%.

tmThueMorse107&colon;

compressedCompresstm

compressed120&comma;−100&comma;−20&comma;−111&comma;75&comma;106&comma;−61&comma;80&comma;0&comma;−60&comma;−82&comma;−12&comma;124&comma;−1&comma;−53&comma;−107&comma;−46&comma;44&comma;−102&comma;69&comma;3&comma;41&comma;36&comma;66&comma;−47&comma;44&comma;12&comma;−2&comma;36&comma;−106&comma;−28&comma;57&comma;−41&comma;117&comma;−82&comma;115&comma;−82&comma;−17&comma;−29&comma;−36&comma;−50&comma;127&comma;−82&comma;−18&comma;−17&comma;−1&comma;126&comma;−10&comma;−24&comma;−9&comma;127&comma;−3&comma;−17&comma;−65&comma;−17&comma;127&comma;−106&comma;−9&comma;110&comma;−1&comma;87&comma;−9&comma;125&comma;−6&comma;−9&comma;−89&comma;−5&comma;105&comma;−66&comma;−35&comma;127&comma;−5&comma;−69&comma;−9&comma;−81&comma;−9&comma;−45&comma;124&comma;−38&comma;−65&comma;−34&comma;79&comma;−13&comma;105&comma;−1&comma;122&comma;63&comma;−51&comma;−73&comma;−5&comma;111&comma;127&comma;−9&comma;−2&comma;−11&comma;126&comma;−102&comma;111&comma;−9&comma;−33&comma;&comma;⋯ 92487 Array entries not shown

(5)

1.numelemscompressedlengthtm

0.9907413000

(6)

See Also

copyright

readbytes

rtable

StringTools

Uncompress

writebytes