mem_compress

mem_compress compresses a string which may contain 0-characters.

ssCompressed = mem_compress(ssString)

Return Value

ssCompressed is the compressed string. The function inserts an 8 byte long header at the beginning of the string. The header starts with the 4 characters gzc\0 followed by a 32-Bit value in little endian byte-order (Intel) which contains the string length of the uncompressed string.

Parameters

ssString

ssString is a scalar string.

Example

filename = GetRootDirectory() + "/script/mn_grid.ic";
fp = fopen(filename, "r");
s = fread(fp, "char");
fclose(fp);
c = mem_compress(s);
print "Size uncompressed:", strlen(s);
print "Size compressed:", mem_len(c);

Output:

Size uncompressed:
91099.0000
Size compressed:
17992.0000

Comment

This function uses the zlib-Library (http://www.gzip.org/zlib/). Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler.

UniPlot verwendet Unicode-Strings, die zwei Bytes pro Zeichen verwenden (UTF-16). Die Funktion mem_compress verwendet nur jeweils die unteren Bytes des Unicode-Strings.

Müssen alle Bytes des Unicode-Strings komprimiert werden, können die Funktionen mem_unpack und mem_pack vor dem Komprimieren bzw. nach dem Dekomprimieren verwendet werden:

* mc = mem_compress(mem_unpack("你们好"))
* print mem_pack(mem_uncompress(mc))
你们好

History

Version Description
5.0.0 Unicode strings.
4.2.0 New

id-1359285