Don't run _getInfo in constructor.

This commit is contained in:
Young Hahn
2011-11-10 00:42:03 -05:00
parent 7d430f77e5
commit 2ea555e5dc

View File

@@ -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.