Package squidpony
Class LZSPlus
java.lang.Object
squidpony.LZSPlus
public final class LZSPlus extends Object
LZ-String compression, taking Strings and compressing them to other Strings, optionally with some encryption.
This role was performed by the BlazingChain library,
which was a dependency of squidlib-extra, but recent developments have allowed all dependencies to be removed other
than SquidLib, while also probably reducing memory usage by a fair amount. The actual implementation of this class is
very unusual, with the LZ-String encoding part derived from
rufushuang's lz-string4java (which is a port of
pieroxy's lz-string), while the encryption-like part (which is not
very strong) was added in SquidLib. This uses
Created by Tommy Ettinger on 7/13/2017.
Garbler
to do the encryption and LZSEncoding
to do the
compression; LZSEncoding uses the original JavaScript lz-string library almost verbatim when run on GWT, so it
performs better than code that has been compiled to JavaScript from Java by GWT, and it performs like Java when run
on a real JVM.
Created by Tommy Ettinger on 7/13/2017.
-
Constructor Summary
Constructors Constructor Description LZSPlus()
-
Method Summary
Modifier and Type Method Description static String
compress(String uncompressedStr)
Compresses the given text using LZ-String compression; does not encrypt the result.static String
compress(String uncompressedStr, long[] keys)
Compresses the given text using LZ-String compression and encrypts (somewhat) the compressed result so it can't be read back without the same keys as a long array.static String
decompress(String compressed)
Decompresses text that was compressed with LZ-String compression; does not reverse decryption so it can only decompress Strings produced bycompress(String)
, orcompress(String, long[])
with an empty or null keys parameter.static String
decompress(String compressed, long[] keys)
Decompresses text that was compressed with LZ-String compression, reversing any encryption if the keys long array matches the long array passed tocompress(String, long[])
(keys can be null if no array was passed).
-
Constructor Details
-
Method Details
-
compress
Compresses the given text using LZ-String compression; does not encrypt the result.- Parameters:
uncompressedStr
- text to compress- Returns:
- a compressed version of the given text
-
compress
Compresses the given text using LZ-String compression and encrypts (somewhat) the compressed result so it can't be read back without the same keys as a long array. Shorter long arrays give less security to encryption, though there isn't much security to begin with. You can produce a decent-quality array for this purpose withGarbler.makeKeyArray(int, String)
; the size parameter could reasonably be anywhere from 2 to 32. If the keys array is null or empty, this only compresses and does not perform an additional encryption step.- Parameters:
uncompressedStr
- text to compress and optionally encryptkeys
- the long array that will be used to encrypt the output, and will be required to decrypt the result; may be null- Returns:
- a compressed and optionally encrypted version of the given text
-
decompress
Decompresses text that was compressed with LZ-String compression; does not reverse decryption so it can only decompress Strings produced bycompress(String)
, orcompress(String, long[])
with an empty or null keys parameter.- Parameters:
compressed
- text that was compressed bycompress(String)
- Returns:
- the original text, decompressed from the given text
-
decompress
Decompresses text that was compressed with LZ-String compression, reversing any encryption if the keys long array matches the long array passed tocompress(String, long[])
(keys can be null if no array was passed).- Parameters:
compressed
- text that was compressed bycompress(String, long[])
keys
- the long array that was used to encrypt the output, and must match to decrypt the result; may be null- Returns:
- the original text, decompressed and decrypted from compressed
-