In [9]:
import lzstring
import requests

Python

In [14]:
txt = open("lordoftherings.txt").read()
In [15]:
len(txt)
Out[15]:
1018696
In [16]:
x = lzstring.LZString()
In [19]:
%%time
s = x.compressToBase64(txt)
print("length", len(s))
length 515072
CPU times: user 1.42 s, sys: 15.9 ms, total: 1.44 s
Wall time: 1.44 s
In [20]:
with open("lordoftherings_compressed.txt", "w") as f:
    f.write(s)
In [21]:
!ls -lah lord*
-rw-r--r-- 1 root root 1018K May  2 04:31 lordoftherings.txt
-rw-r--r-- 1 root root  503K May  2 04:33 lordoftherings_compressed.txt

Javascript

<script type="text/javascript" src="lz-string.min.js"></script>
<script>
fetch('<url>/lordoftherings_compressed.txt').then(rs => rs.text())
        .then((data) => {
            string = LZString.decompressFromBase64(data);
            document.querySelector('body').innerHTML = string
        })
</script>
In [ ]: