ZLIB File Format - Maple Programming Help

Home : Support : Online Help : Programming : Input and Output : File Formats : Formats/ZLIB

ZLIB File Format

zlib file format

Description

 • ZLIB is a data compression format, used primarily for in-transit data rather than file storage.
 • The Import command can encode and decode data in this format, and the ArrayTools[Compress] and ArrayTools[Uncompress] commands also support it.
 • The zlib compression algorithm is taken from the zlib library written by Jean-loup Gailly and Mark Adler. See http://zlib.net.

Notes

 • Content-Type: application/zlib

Examples

Write some data directly to a ByteArray in zlib format.

 > $\mathrm{data}≔\mathrm{Export}\left("The quick brown fox jumped over the lazy dog",\mathrm{target}=\mathrm{direct},\mathrm{format}="ZLIB"\right)$
 ${\mathrm{data}}{≔}\left[\begin{array}{ccccccccccccccccccccccccccccccccccccccccccccccccccc}{120}& {-100}& {11}& {-55}& {72}& {85}& {40}& {44}& {-51}& {76}& {-50}& {86}& {72}& {42}& {-54}& {47}& {-49}& {83}& {72}& {-53}& {-81}& {80}& {-56}& {42}& {-51}& {45}& {72}& {77}& {81}& {-56}& {47}& {75}& {45}& {82}& {40}& {1}& {-54}& {-25}& {36}& {86}& {85}& {42}& {-92}& {-28}& {-89}& {3}& {0}& {107}& {-109}& {16}& {48}\end{array}\right]$ (1)

Read the data back and uncompress it.

 > $\mathrm{arr}≔\mathrm{Import}\left(\mathrm{data},\mathrm{source}=\mathrm{direct},\mathrm{format}="ZLIB"\right)$
 ${\mathrm{arr}}{≔}\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccc}{84}& {104}& {101}& {32}& {113}& {117}& {105}& {99}& {107}& {32}& {98}& {114}& {111}& {119}& {110}& {32}& {102}& {111}& {120}& {32}& {106}& {117}& {109}& {112}& {101}& {100}& {32}& {111}& {118}& {101}& {114}& {32}& {116}& {104}& {101}& {32}& {108}& {97}& {122}& {121}& {32}& {100}& {111}& {103}\end{array}\right]$ (2)

Retrieve the original message.

 > $\mathrm{StringTools}:-\mathrm{FromByteArray}\left(\mathrm{arr}\right)$
 ${"The quick brown fox jumped over the lazy dog"}$ (3)

References

 [RFC6713] Levine, J., The 'application/zlib' and 'application/gzip' Media Types, RFC 6713, August 2012.