Sketch of using map table + map index if present for zxystream.

This commit is contained in:
Young Hahn
2014-12-10 03:07:32 -05:00
parent bdfa6a65a4
commit 067db2ce70
3 changed files with 55 additions and 1 deletions

BIN
test/fixtures/unindexed.mbtiles vendored Normal file

Binary file not shown.

View File

@@ -20,6 +20,7 @@ tape('zxystream default batch', function(assert) {
assert.deepEqual(stream.offset, 0, 'sets stream.offset = 0');
stream.on('data', function(lines) {
assert.equal(stream.table, 'map');
output += lines;
called++;
});
@@ -52,6 +53,7 @@ tape('zxystream batch = 10', function(assert) {
assert.deepEqual(stream.offset, 0, 'sets stream.offset = 0');
stream.on('data', function(lines) {
assert.equal(stream.table, 'map');
output += lines;
called++;
});
@@ -73,6 +75,48 @@ tape('zxystream batch = 10', function(assert) {
});
});
tape('zxystream unindexed', function(assert) {
new MBTiles(__dirname + '/fixtures/unindexed.mbtiles', function(err, s) {
assert.ifError(err);
source = s;
assert.end();
});
});
tape('zxystream unindexed zxystream', function(assert) {
var stream = source.createZXYStream();
var output = '';
var called = 0;
assert.deepEqual(stream.source, source, 'sets stream.source');
assert.deepEqual(stream.batch, 1000, 'sets stream.batch = 1000');
assert.deepEqual(stream.offset, 0, 'sets stream.offset = 0');
stream.on('data', function(lines) {
assert.equal(stream.table, 'tiles');
output += lines;
called++;
});
stream.on('end', function() {
var queue = output.toString().split('\n');
assert.equal(queue.length, 286);
assert.equal(called, 1, 'emitted data x27 times');
checkTile(queue);
function checkTile(queue) {
if (!queue.length) return assert.end();
var zxy = queue.shift();
if (!zxy) return checkTile(queue);
zxy = zxy.split('/');
source.getTile(zxy[0], zxy[1], zxy[2], function(err, buffer, headers) {
assert.equal(!err && (buffer instanceof Buffer), true, zxy.join('/') + ' exists');
checkTile(queue);
});
}
});
});
tape('zxystream empty', function(assert) {
new MBTiles(__dirname + '/fixtures/non_existent.mbtiles', function(err, s) {
assert.ifError(err);