Merge.
This commit is contained in:
@@ -55,9 +55,6 @@ function MBTiles(uri, callback) {
|
||||
this._batchSize = +uri.query.batch;
|
||||
Step(function() {
|
||||
mbtiles._db = new sqlite3.Database(mbtiles.filename, this);
|
||||
}, function(err) {
|
||||
if (err) throw err;
|
||||
mbtiles._setup(this);
|
||||
}, function(err) {
|
||||
if (err) throw err;
|
||||
fs.stat(mbtiles.filename, this);
|
||||
@@ -174,7 +171,7 @@ MBTiles.prototype.getTile = function(z, x, y, callback) {
|
||||
} else {
|
||||
var options = {
|
||||
'Content-Type': MBTiles.utils.getMimeType(row.tile_data),
|
||||
'Last-Modified': mbtiles._stat.mtime,
|
||||
'Last-Modified': new Date(mbtiles._stat.mtime).toUTCString(),
|
||||
'ETag': mbtiles._stat.size + '-' + Number(mbtiles._stat.mtime)
|
||||
};
|
||||
return callback(null, row.tile_data, options);
|
||||
@@ -216,21 +213,22 @@ MBTiles.prototype.getGrid = function(z, x, y, callback) {
|
||||
if (err) return callback(err);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
? 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 });
|
||||
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);
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -385,18 +383,24 @@ MBTiles.prototype.startWriting = function(callback) {
|
||||
if (typeof callback !== 'function') throw new Error('Callback needed');
|
||||
if (!this.open) return callback(new Error('MBTiles not yet loaded'));
|
||||
|
||||
// Sets the synchronous flag to OFF for (much) faster inserts.
|
||||
// See http://www.sqlite3.org/pragma.html#pragma_synchronous
|
||||
|
||||
var mbtiles = this;
|
||||
if (!this._isWritable) {
|
||||
this._isWritable = 1;
|
||||
this._clearCaches();
|
||||
this._db.run('PRAGMA synchronous=OFF', callback);
|
||||
} else {
|
||||
this._isWritable++;
|
||||
return callback(null);
|
||||
}
|
||||
Step(function() {
|
||||
mbtiles._setup(this);
|
||||
}, function(err) {
|
||||
if (err) throw err;
|
||||
// Sets the synchronous flag to OFF for (much) faster inserts.
|
||||
// See http://www.sqlite3.org/pragma.html#pragma_synchronous
|
||||
if (!mbtiles._isWritable) {
|
||||
mbtiles._isWritable = 1;
|
||||
mbtiles._clearCaches();
|
||||
mbtiles._db.run('PRAGMA synchronous=OFF', this);
|
||||
} else {
|
||||
mbtiles._isWritable++;
|
||||
this();
|
||||
}
|
||||
}, function(err) {
|
||||
return callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
MBTiles.prototype._clearCaches = function() {
|
||||
|
||||
Reference in New Issue
Block a user