Last active
August 29, 2015 14:09
-
-
Save mobiusklein/8945d55b9b0f86f2bceb to your computer and use it in GitHub Desktop.
Different methods of testing browserify-zlib against python gzip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var zlib = require("zlib"), | |
fs = require("fs"); | |
var datum = new Buffer(JSON.stringify({cats: [1, 2]})) | |
zlib.gzip(datum, function(error, results){ | |
if (error !== null){ | |
throw error | |
} | |
console.log(results) | |
fs.writeFileSync("data.json.gz", results) | |
zlib.gunzip(results, function(errun, resun){ | |
console.log(errun, resun.toString('utf8')) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gzip | |
import json | |
def main(): | |
df = gzip.open("data.json.gz", 'wb') | |
jd = dict(cats=["a", "b"]) | |
data = json.dumps(jd) | |
df.write(data) | |
df.close() | |
df = gzip.open("data.json.gz", 'rb') | |
#data = json.load(df) | |
data = df.read() | |
print(data) | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
‹¦€eTÿdata.json «VJN,)V²RˆVJTÒQPJRŠ ýÑ»“ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zlib = require('zlib') | |
fs = require('fs') | |
data = fs.readFileSync('data.json.gz') | |
buffered = new Buffer(data, "utf8") | |
console.log(buffered) | |
zlib.gunzip(buffered, function(err, res){ | |
console.log(err, res.toString("utf8")) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script src='main.js'></script> | |
<script type="text/javascript"> | |
$(function(){ | |
console.log("Send request") | |
$.ajax({url: "/data.json.gz"}) | |
.success(function(data, status, req){ | |
console.log(status) | |
window.COMPRESSED_DATA = data | |
window.BUFFERED_COMPRESSED_DATA = new buffer.Buffer(data) | |
console.log(data) | |
window.DECOMPRESSED_DATA = zlib.gunzipSync(BUFFERED_COMPRESSED_DATA) | |
}).error(function(error, message, splat){ | |
console.log(arguments) | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment