v1.12.0

JSXCompressor – Python script

Posted on December 2, 2009 by Alfred Wassermann

A simple Python script to compress a file to be uncompressed by the JavaScript JSXCompressor is the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
## -*- coding: utf-8 -*-
import sys
import os
import urllib
import base64
import zlib

if __name__ == '__main__':
    if len(sys.argv)<1:
        sys.stderr.write("call: python compress.py filename\n")
        sys.exit(0) 
    filename = sys.argv[1]
    if not os.path.exists(filename):
        sys.stderr.write("file '%s' not found\n" % filename)
        sys.exit(0) 
    f = open(filename, "r")
    text = f.read()
    text = base64.b64encode(zlib.compress(urllib.quote(text)))
    print text

It can be downloaded here.

To all posts