Don't run _getInfo in constructor.
This commit is contained in:
+11
-11
@@ -89,10 +89,10 @@ MBTiles.prototype._open = function(uri) {
|
|||||||
mbtiles._setup(this);
|
mbtiles._setup(this);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) return error(err);
|
if (err) return error(err);
|
||||||
mbtiles._getInfo(this);
|
fs.stat(mbtiles.filename, this);
|
||||||
}, function(err, info) {
|
}, function(err, stat) {
|
||||||
if (err) return error(err);
|
if (err) return error(err);
|
||||||
mbtiles._info = info;
|
mbtiles._stat = stat;
|
||||||
fs.watchFile(mbtiles.filename, {
|
fs.watchFile(mbtiles.filename, {
|
||||||
// Indicates that the node process may exit if the file watcher
|
// Indicates that the node process may exit if the file watcher
|
||||||
// is the only thing in the event loop.
|
// is the only thing in the event loop.
|
||||||
@@ -300,13 +300,8 @@ MBTiles.prototype._getInfo = function(callback) {
|
|||||||
info.scheme = 'tms';
|
info.scheme = 'tms';
|
||||||
info.basename = path.basename(mbtiles.filename);
|
info.basename = path.basename(mbtiles.filename);
|
||||||
info.id = path.basename(mbtiles.filename, path.extname(mbtiles.filename));
|
info.id = path.basename(mbtiles.filename, path.extname(mbtiles.filename));
|
||||||
|
info.filesize = mbtiles._stat.size;
|
||||||
Step(function() {
|
Step(function() {
|
||||||
fs.stat(mbtiles.filename, this);
|
|
||||||
}, function(err, stat) {
|
|
||||||
if (err) return callback(err);
|
|
||||||
mbtiles._stat = stat;
|
|
||||||
info.filesize = stat.size;
|
|
||||||
|
|
||||||
var end = this;
|
var end = this;
|
||||||
mbtiles._db.all('SELECT name, value FROM metadata', function(err, rows) {
|
mbtiles._db.all('SELECT name, value FROM metadata', function(err, rows) {
|
||||||
if (rows) for (var i = 0; i < rows.length; i++) {
|
if (rows) for (var i = 0; i < rows.length; i++) {
|
||||||
@@ -418,8 +413,13 @@ MBTiles.prototype._getInfo = function(callback) {
|
|||||||
// - @param {Function(err, data)} callback
|
// - @param {Function(err, data)} callback
|
||||||
MBTiles.prototype.getInfo = function(callback) {
|
MBTiles.prototype.getInfo = function(callback) {
|
||||||
if (typeof callback !== 'function') throw new Error('Callback needed');
|
if (typeof callback !== 'function') throw new Error('Callback needed');
|
||||||
if (!this._info || !this.open) return callback(new Error('MBTiles not yet loaded'));
|
if (!this.open) return callback(new Error('MBTiles not yet loaded'));
|
||||||
callback(null, this._info);
|
if (this._info) return callback(null, this._info);
|
||||||
|
var mbtiles = this;
|
||||||
|
mbtiles._getInfo(function(err, info) {
|
||||||
|
mbtiles._info = info;
|
||||||
|
return callback(err, info);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Puts the MBTiles tilestore into write mode.
|
// Puts the MBTiles tilestore into write mode.
|
||||||
|
|||||||
Reference in New Issue
Block a user