switch to using native zlib, inflate works, odd test failures for deflate
This commit is contained in:
+36
-7
@@ -2,7 +2,7 @@ var _ = require('underscore'),
|
|||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
Step = require('step'),
|
Step = require('step'),
|
||||||
crypto = require('crypto'),
|
crypto = require('crypto'),
|
||||||
_zlib = require('_zlib'),
|
zlib = require('zlib'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
url = require('url'),
|
url = require('url'),
|
||||||
qs = require('querystring'),
|
qs = require('querystring'),
|
||||||
@@ -215,8 +215,9 @@ MBTiles.prototype.getGrid = function(z, x, y, callback) {
|
|||||||
}
|
}
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
|
/*
|
||||||
try {
|
try {
|
||||||
var grid = _zlib.inflate(
|
var grid = zlib.inflate(
|
||||||
!Buffer.isBuffer(row.grid)
|
!Buffer.isBuffer(row.grid)
|
||||||
? new Buffer(row.grid, 'binary')
|
? new Buffer(row.grid, 'binary')
|
||||||
: row.grid
|
: row.grid
|
||||||
@@ -231,6 +232,24 @@ MBTiles.prototype.getGrid = function(z, x, y, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
|
*/
|
||||||
|
|
||||||
|
zlib.inflate(!Buffer.isBuffer(row.grid)
|
||||||
|
? new Buffer(row.grid, 'binary')
|
||||||
|
: row.grid
|
||||||
|
, function(err,buffer) {
|
||||||
|
if (err) {
|
||||||
|
return callback(new Error('Grid is invalid:' + err.message));
|
||||||
|
}
|
||||||
|
var data = rows.reduce(function(memo, r) {
|
||||||
|
memo[r.key_name] = JSON.parse(r.key_json);
|
||||||
|
return memo;
|
||||||
|
}, {});
|
||||||
|
var result = _(JSON.parse(buffer.toString())).extend({ data: data });
|
||||||
|
|
||||||
|
callback(null, result);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -565,13 +584,23 @@ MBTiles.prototype.putGrid = function(z, x, y, data, callback) {
|
|||||||
var id = crypto.createHash('md5').update(json).digest('hex');
|
var id = crypto.createHash('md5').update(json).digest('hex');
|
||||||
if (!this._gridCache[id]) {
|
if (!this._gridCache[id]) {
|
||||||
// This corresponds to the grid_utfgrid table.
|
// This corresponds to the grid_utfgrid table.
|
||||||
this._gridCache[id] = _zlib.deflate(new Buffer(json, 'utf8'));
|
|
||||||
|
|
||||||
// This corresponds to the grid_key table.
|
/*
|
||||||
this._keyCache[id] = Object.keys(data.data || {});
|
this._gridCache[id] = zlib.deflate(new Buffer(json, 'utf8'));
|
||||||
|
*/
|
||||||
|
|
||||||
// This corresponds to the keymap table.
|
Step(function() {
|
||||||
_(this._dataCache).extend(data.data || {});
|
zlib.deflate(new Buffer(json, 'utf8'),this);
|
||||||
|
}, function(err,buffer) {
|
||||||
|
if (err) return callback(err);
|
||||||
|
this._gridCache[id] = buffer;
|
||||||
|
// This corresponds to the grid_key table.
|
||||||
|
this._keyCache[id] = Object.keys(data.data || {});
|
||||||
|
|
||||||
|
// This corresponds to the keymap table.
|
||||||
|
_(this._dataCache).extend(data.data || {});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This corresponds to the map table.
|
// This corresponds to the map table.
|
||||||
|
|||||||
Reference in New Issue
Block a user