From 2ea555e5dce80576249fe16abb2e0bd00bfc2df3 Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Thu, 10 Nov 2011 00:42:03 -0500 Subject: [PATCH] Don't run _getInfo in constructor. --- lib/mbtiles.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/mbtiles.js b/lib/mbtiles.js index 90be990..7d8258b 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -89,10 +89,10 @@ MBTiles.prototype._open = function(uri) { mbtiles._setup(this); }, function(err) { if (err) return error(err); - mbtiles._getInfo(this); - }, function(err, info) { + fs.stat(mbtiles.filename, this); + }, function(err, stat) { if (err) return error(err); - mbtiles._info = info; + mbtiles._stat = stat; fs.watchFile(mbtiles.filename, { // Indicates that the node process may exit if the file watcher // is the only thing in the event loop. @@ -300,13 +300,8 @@ MBTiles.prototype._getInfo = function(callback) { info.scheme = 'tms'; info.basename = path.basename(mbtiles.filename); info.id = path.basename(mbtiles.filename, path.extname(mbtiles.filename)); + info.filesize = mbtiles._stat.size; 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; mbtiles._db.all('SELECT name, value FROM metadata', function(err, rows) { if (rows) for (var i = 0; i < rows.length; i++) { @@ -418,8 +413,13 @@ MBTiles.prototype._getInfo = function(callback) { // - @param {Function(err, data)} callback MBTiles.prototype.getInfo = function(callback) { if (typeof callback !== 'function') throw new Error('Callback needed'); - if (!this._info || !this.open) return callback(new Error('MBTiles not yet loaded')); - callback(null, this._info); + if (!this.open) return callback(new Error('MBTiles not yet loaded')); + 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.