PackageDescription: String-Compression-Support


String - Compression - Support

Last published: July 26, 2007 by 'rmba'

Defines 0 Classes
Extends 2 Classes


Syntactic sugar for deflating and inflating strings using the built in VM based ZLib interface.

Some usage ideas:
1. Store compress string data in external files.
2. Send compressed bytes across wire protocols for image to image communication.
3. Store compressed bytes as literals in methods to avoid dependency on external files. e.g. large XML resources

Sample API usage:

aString asDeflatedBytes - Deflated bytes.
aByteArray asInflatedString - Inflated original string.
String fromDeflatedBytes: aByteArray - Inflated original string.

To store large strings as method literals, convert the deflated bytes to an integer and paste the literal into your method. e.g.
'String sample' asDeflatedBytes asLargePositiveInteger

To reconstitute just reverse the process e.g.

3652440387086394313189230330778174064955377742164360636481199364314692747001856 asByteArray asInflatedString

N.B Above sample is pathological since there is a minor overhead caused by the compression machinery in the result so this is not very useful for tiny strings < 21 bytes.

When optionally used with an XML serialisation framework like SIXX then large objects graphs can be stored efficiently as compressed xml literals in unit test methods e.g.

aComplexTestObject sixxString asDeflatedBytes asLargePositiveInteger

Released as open source under the MIT license.
2007 Denis Johnson