Skip to tool

LZ-String Decompress and Compress

Decompress or compress LZ-String text (decompressFromEncodedURIComponent, Base64, UTF16), pasted or from files. Decodes TypeScript playground #code/ text.

Runs in your browser — your input is processed on this device and never uploaded.

Input

Pick up to 5 UTF-8 text files of up to 100 MiB each, or paste text. Each file gets its own result. Decompress ignores line breaks, and in the uri form a space counts as +. A whole share link works too.

Auto decompresses text that is LZ-String data, including a pasted share link, and compresses anything else. Decompress and Compress force the direction.

Which LZ-String form to use: uri (compressToEncodedURIComponent, the form used in links), base64 (compressToBase64) or utf16 (compressToUTF16). Compress writes this form. Decompress reads it first, then tries the other two and says which one it used.

Result

Results appear here.

About this tool

On this page

What is LZ-String?

LZ-String is a JavaScript library that compresses text into other text. Web apps use it to fit their state into a link or into browser storage. The TypeScript playground, for example, puts your code in the link after #code/ this way.

This tool turns LZ-String text back into the original, or compresses text with LZ-String. Pick text files and get one file back for each, or paste the text. Ports of the library for other languages are often named LZString or lzstring.

LZ-String options

Text or text files
Up to 5 UTF-8 text files of up to 100 MiB each, or pasted text. Each file runs on its own and gets its own result.
Action
Auto, the default, decompresses text that is LZ-String data and compresses anything else. Decompress and Compress force the direction.
Form
uri, base64 or utf16, each matching a pair of library functions listed below. uri is the default and the form used in links. Compress writes this form. Decompress reads it first and, when the text is not in that form, tries the other two and says which one it used.
File name
Optional. Compress adds .lzstring and Decompress removes it, so notes.txt becomes notes.txt.lzstring and back. Pasted text comes out as output.lzstring or output.txt.
  • When decompressing, line breaks, spaces and a leading byte-order mark are ignored, and in the uri form a space counts as +, because some web forms turn + into a space.
  • A whole share link works too. The data is taken from after #code/, the part after #, a query value or the last part of the path, and URL encoding is removed.
  • Under Auto, LZ-String text that has been cut off no longer decodes exactly, so it is compressed instead. Choose Decompress to get back the text up to the cut, as a file marked .partial, when at least 1 KiB of it can be read.
  • The result is up to 200 MiB, as a file you can download. A shorter result also shows as text you can copy.
  • A file that is not UTF-8 text, such as an image or a ZIP, is refused. LZ-String only works on text.
  • Large text with almost no repeats, such as random Base64, can be refused too: LZ-String never resets its dictionary, and on that kind of text it would outgrow the memory this tool allows.

Each form matches a pair of functions in the library:

uri
compressToEncodedURIComponent and decompressFromEncodedURIComponent
base64
compressToBase64 and decompressFromBase64
utf16
compressToUTF16 and decompressFromUTF16
  1. Copy the whole link, or only the text after #code/.
  2. Open the Text tab, paste it, keep Action on Auto, and run.

For example, this text from after #code/ in a playground link:

MYewdgzgLgBA5gJwKZKgSzHAXDaCNwwC8MARABZIA2VIpA3AFCiQhVIB0tcAFIiukwBKJkA

comes back as the two lines of code it holds:

const greeting: string = "hello";
console.log(greeting);

Why use LZ-String instead of Base64

Base64 makes text about a third longer. LZ-String compresses first, so long text with repeats, such as code or JSON, usually comes out shorter than it went in while staying safe for a link. Very short text can come out longer.

Reading it back is the common job: a share link or a stored value holds data you want to see, and the library's output is unreadable until it is decompressed.

LZ-String alternatives

If the text starts with H4sI, it is gzip data in Base64, not LZ-String. For plain Base64 or percent-encoded text, use the Base64 Encoder and Decoder or the URL Encoder and Decoder.

To compress a whole file for storage or download rather than for a link, a standard format such as Gzip is the safer choice, since every system can open it. In your own code, the lz-string package on npm does the same job as this tool.

Things to know about LZ-String

pieroxy published LZ-String in 2013. It is a variant of LZW compression that writes its output in a chosen alphabet instead of raw bytes.

The utf16 form stores 15 bits in each character and adds 32 to every value, so it never produces control characters.

Older TypeScript playground links use #src= instead of #code/. That part is ordinary URL encoding, not LZ-String, so open it with the URL Encoder and Decoder.

LZ-String text can expand a great deal: a short string can stand for megabytes of output. Decompressing stops at 200 MiB of output, so one crafted link cannot grow without limit.

Warning

LZ-String is not encryption. Anyone with the link can read what it holds, so keep passwords and keys out of LZ-String links.

Browse

Find similar tools by category or tag.