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

View File

@@ -215,26 +215,25 @@ MBTiles.prototype.getGrid = function(z, x, y, callback) {
}
if (err) return callback(err);
try {
var grid = zlib.inflate(
!Buffer.isBuffer(row.grid)
zlib.inflate(!Buffer.isBuffer(row.grid)
? new Buffer(row.grid, 'binary')
: row.grid
).toString();
var data = rows.reduce(function(memo, r) {
memo[r.key_name] = JSON.parse(r.key_json);
return memo;
}, {});
var result = _(JSON.parse(grid)).extend({ data: data });
} catch (err) {
return callback(new Error('Grid is invalid'));
}
var options = {
'Content-Type': 'text/javascript',
'Last-Modified': new Date(that._stat.mtime).toUTCString(),
'ETag': that._stat.size + '-' + Number(that._stat.mtime)
};
callback(null, result, options);
, 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 });
var options = {
'Content-Type': 'text/javascript',
'Last-Modified': new Date(that._stat.mtime).toUTCString(),
'ETag': that._stat.size + '-' + Number(that._stat.mtime)
};
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');
if (!this._gridCache[id]) {
// 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._keyCache[id] = Object.keys(data.data || {});
// This corresponds to the keymap table.
_(this._dataCache).extend(data.data || {});
// This corresponds to the keymap table.
_(that._dataCache).extend(data.data || {});
}
);
}
// This corresponds to the map table.

View File

@@ -30,14 +30,13 @@
],
"dependencies": {
"optimist": "0.2.x",
"sqlite3": "~2.0.17",
"sqlite3": "~2.1.1",
"step": "0.0.x",
"sphericalmercator": "1.0.x",
"underscore": "1.1.x",
"zlib": "1.0.x"
"underscore": "1.1.x"
},
"engines": {
"node": ">= 0.4.0"
"node": ">= 0.6.0"
},
"scripts": {
"test": "expresso"