From f85ca16c6230313dfab5c4e4d8596eba9ef360e6 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 19 Apr 2013 16:16:20 +0200 Subject: [PATCH] Change LZMA expected encoding from HEX to base64, reducing its size --- NEWS.md | 1 + lib/cartodb/server_options.js | 11 ++--------- test/acceptance/server.js | 16 +++++----------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9940ab85..55be5b21 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ * Interactivity only specified in layergroup config * Embed cache_buster within token * Use ISO format for last_modified timestamp +* Expected LZMA encoding changed to base64 1.1.10 ------ diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index daf19f7f..2d692dd8 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -286,15 +286,8 @@ module.exports = function(){ //console.log("type of req.query.lzma is " + typeof(req.query.lzma)); //console.log("req.query.lzma is " + req.query.lzma); - // Decode - var lzma = []; - for (var i=0; i 127 ) num = 127-num; - //console.log(i + " hex: " + hex + " decodes as " + num); - lzma.push( num ); - } + // Decode (from base64) + var lzma = new Buffer(req.query.lzma, 'base64'); // Decompress //console.log("LZMA decompression starts with " + lzma); diff --git a/test/acceptance/server.js b/test/acceptance/server.js index cddc1cd4..1b91a207 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -18,19 +18,13 @@ var server = new CartodbWindshaft(serverOptions); server.setMaxListeners(0); // Utility function to compress & encode LZMA -function lzma_compress_to_hex(payload, mode, callback) { +function lzma_compress_to_base64(payload, mode, callback) { var HEX = [ '0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f' ]; LZMA.compress(payload, mode, function(ints) { - for (var i=0; i> 4; - var lo = ints[i] & 0x0f; - ints[i] = HEX[hi] + HEX[lo]; - }; - var hex = ints.join(''); - callback(null, hex); + var base64 = new Buffer(ints).toString('base64'); + callback(null, base64); }, function(percent) { //console.log("Compressing: " + percent + "%"); @@ -814,14 +808,14 @@ suite('server', function() { function compressQuery () { //console.log("Compressing starts"); var next = this; - lzma_compress_to_hex(JSON.stringify(qo), 1, this); + lzma_compress_to_base64(JSON.stringify(qo), 1, this); //cosole.log("compress returned " + x ); }, function sendRequest(err, lzma) { //console.log("Compressing ends: " + typeof(lzma) + " - " + lzma); assert.response(server, { headers: {host: 'localhost'}, - url: '/tiles/test_table/15/16046/12354.png?lzma=' + lzma, + url: '/tiles/test_table/15/16046/12354.png?lzma=' + encodeURIComponent(lzma), method: 'GET', encoding: 'binary' },{}, this);