Change LZMA expected encoding from HEX to base64, reducing its size

This commit is contained in:
Sandro Santilli
2013-04-19 16:16:20 +02:00
parent 14953e992f
commit f85ca16c62
3 changed files with 8 additions and 20 deletions

View File

@@ -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
------

View File

@@ -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<req.query.lzma.length/2; ++i) {
var hex = req.query.lzma.substring(i*2, i*2+2);
var num = parseInt(hex, "16");
if ( num > 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);

View File

@@ -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<ints.length; ++i) {
if ( ints[i] < 0 ) ints[i] = 127-ints[i];
var hi = ints[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);