port to >= node-v6

This commit is contained in:
Dane Springmeyer
2012-03-06 18:04:26 -08:00
parent a7bb5d06bc
commit 1190695bf3
2 changed files with 32 additions and 28 deletions
+29 -24
View File
@@ -215,26 +215,25 @@ MBTiles.prototype.getGrid = function(z, x, y, callback) {
} }
if (err) return callback(err); if (err) return callback(err);
try { zlib.inflate(!Buffer.isBuffer(row.grid)
var grid = zlib.inflate(
!Buffer.isBuffer(row.grid)
? new Buffer(row.grid, 'binary') ? new Buffer(row.grid, 'binary')
: row.grid : row.grid
).toString(); , function(err,buffer) {
var data = rows.reduce(function(memo, r) { if (err) {
memo[r.key_name] = JSON.parse(r.key_json); return callback(new Error('Grid is invalid:' + err.message));
return memo; }
}, {}); var data = rows.reduce(function(memo, r) {
var result = _(JSON.parse(grid)).extend({ data: data }); memo[r.key_name] = JSON.parse(r.key_json);
} catch (err) { return memo;
return callback(new Error('Grid is invalid')); }, {});
} var result = _(JSON.parse(buffer.toString())).extend({ data: data });
var options = { var options = {
'Content-Type': 'text/javascript', 'Content-Type': 'text/javascript',
'Last-Modified': new Date(that._stat.mtime).toUTCString(), 'Last-Modified': new Date(that._stat.mtime).toUTCString(),
'ETag': that._stat.size + '-' + Number(that._stat.mtime) 'ETag': that._stat.size + '-' + Number(that._stat.mtime)
}; };
callback(null, result, options); callback(null, result, options);
});
} }
); );
}; };
@@ -582,13 +581,19 @@ MBTiles.prototype.putGrid = function(z, x, y, data, callback) {
var id = data.id || crypto.createHash('md5').update(json).digest('hex'); var id = data.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')); var that = this;
Step(function() {
zlib.deflate(new Buffer(json, 'utf8'),this);
}, function(err,buffer) {
if (err) return callback(err);
that._gridCache[id] = buffer;
// This corresponds to the grid_key table.
that._keyCache[id] = Object.keys(data.data || {});
// This corresponds to the grid_key table. // This corresponds to the keymap table.
this._keyCache[id] = Object.keys(data.data || {}); _(that._dataCache).extend(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.
+3 -4
View File
@@ -30,14 +30,13 @@
], ],
"dependencies": { "dependencies": {
"optimist": "0.2.x", "optimist": "0.2.x",
"sqlite3": "~2.0.17", "sqlite3": "~2.1.1",
"step": "0.0.x", "step": "0.0.x",
"sphericalmercator": "1.0.x", "sphericalmercator": "1.0.x",
"underscore": "1.1.x", "underscore": "1.1.x"
"zlib": "1.0.x"
}, },
"engines": { "engines": {
"node": ">= 0.4.0" "node": ">= 0.6.0"
}, },
"scripts": { "scripts": {
"test": "expresso" "test": "expresso"