diff --git a/lib/mbtiles.js b/lib/mbtiles.js index b93ff8e..ddd1a40 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -392,7 +392,7 @@ MBTiles.prototype.startWriting = function(callback) { if (!this._isWritable) { this._isWritable = 1; this._clearCaches(); - this._db.exec('PRAGMA journal_mode = OFF; PRAGMA locking_mode = EXCLUSIVE; PRAGMA synchronous=OFF; PRAGMA cache_size = 400000;', callback); + this._db.exec('PRAGMA locking_mode = EXCLUSIVE; PRAGMA synchronous=OFF; PRAGMA cache_size = 400000;', callback); } else { this._isWritable++; return callback(null); @@ -613,3 +613,22 @@ MBTiles.prototype.putInfo = function(data, callback) { }); }); }; + +// Copy resume. Optionally retrieve the highest inserted key for resuming a +// tilelive.copy operation. +MBTiles.prototype.copyResume = function(callback) { + if (typeof callback !== 'function') throw new Error('Callback needed'); + if (!this.open) return callback(new Error('MBTiles not yet loaded')); + var mbtiles = this; + Step(function() { + mbtiles._db.get('SELECT zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles ORDER BY z DESC, y DESC, x DESC LIMIT 1', this.parallel()); + mbtiles._db.get('SELECT COUNT(*) AS copied FROM tiles WHERE tile_data IS NOT NULL', this.parallel()); + }, function(err, coords, copied) { + if (err) return callback(err); + // Flip Y coordinate back to XYZ for tilelive API. + if (coords) coords.y = (1 << coords.z) - 1 - coords.y; + if (coords && copied) coords.copied = copied.copied; + return callback(null, coords); + }); +}; +