Compress - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ArrayTools

  

Compress

  

compress a byte sequence

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

Compress(data, opts)

Parameters

data

-

ByteArray or list of integers

opts

-

(optional) equation of the form format = value

Options

• 

format = one of bzip2, gzip, zip, or zlib

  

This option allows a compression format to be specified explicitly. Options are bzip2, gzip, zip, or zlib. The default is zlib.

Description

• 

The Compress(A) command takes the given byte array or list and compresses it into a lossless, more compact format. The return value is a ByteArray.

• 

If A is a list, its contents must be integers between -128 and 127.

Examples

Generate a ByteArray of number-theoretic data and compress it.

OmegaArrayArray1..105,NumberTheory:-NumberOfPrimeFactors,datatype=integer1

CompressedOmegaArrayArrayTools:-CompressOmegaArray

Compare the size of the original with the compressed result.

numelemsOmegaArray,numelemsCompressedOmegaArray

100000,37013

(1)

Generate random data from a discrete uniform statistical distribution between -10 and 10 and compress it with zip format.

dataStatistics:-SampleDiscreteUniform10,10,1000000

originalconvertdata,ByteArray

compressedArrayTools:-Compressoriginal

Compute the compression ratio for this example.

1.numelemscompressednumelemsoriginal

0.8718235000

(2)

Convert a string to a ByteArray and compress it using gzip.

PaulCliffordTextIt was a dark and stormy night; the rain fell in torrents - except at occasional intervals, when it was checked by a violent gust of wind which swept up the streets (for it is in London that our scene lies), rattling along the housetops, and fiercely agitating the scanty flame of the lamps that struggled against the darkness.:

originalStringTools:-ToByteArrayPaulCliffordText

compressedArrayTools:-Compressoriginal,format=gzip

Compute the compression ratio for this example.

1.numelemscompressednumelemsoriginal

0.2996941896

(3)

Compatibility

• 

The ArrayTools[Compress] command was introduced in Maple 2015.

• 

For more information on Maple 2015 changes, see Updates in Maple 2015.

• 

The ArrayTools[Compress] command was updated in Maple 2018.

• 

The format option was updated in Maple 2018.

See Also

ArrayTools

ArrayTools[Uncompress]

copyright

FileTools[Compressed]

StringTools[Compress]

type/ByteArray