New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tilelive

Package Overview
Dependencies
Maintainers
5
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tilelive - npm Package Compare versions

Comparing version 4.3.3 to 4.4.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## 4.4.0
* Remove deprecated tilelive.copy method in favor of CopyTask.
* Rewrite tilelive-copy with better interface and detection of protocols.
## 4.3.3

@@ -2,0 +7,0 @@

4

lib/copytask.js

@@ -23,3 +23,3 @@ var tilelive = require('..');

this.ended = null;
this.job = job;
this.job = job || '/tmp/tilelive-' + (+new Date) + '.job';
this.formats = [];

@@ -106,2 +106,4 @@ this.cache = { tile: {}, grid: {} };

CopyTask.prototype.start = function(callback) {
callback = callback || new Function;
var task = this

@@ -108,0 +110,0 @@ if (!this.started) this.started = Date.now();

@@ -218,164 +218,1 @@ var tilelive = exports;

function totalTiles(x, y, z) {
for (var total = 0, i = 0; i <= z; i++, x *= 2, y *= 2) {
total += x * y;
}
return total;
}
tilelive.copy = function(args, callback) {
if (typeof args.source.getTile !== 'function') throw new Error('source must implement the tilesource interface');
if (typeof args.sink.putTile !== 'function') throw new Error('sink must implement the tilesink interface');
if (!Array.isArray(args.bbox) || args.bbox.length !== 4) throw new Error('bbox must have four lat/long coordinates');
if (args.bbox[0] < -180) throw new Error('bbox has invalid west value');
if (args.bbox[1] < -85.05112877980659) throw new Error('bbox has invalid south value');
if (args.bbox[2] > 180) throw new Error('bbox has invalid east value');
if (args.bbox[3] > 85.05112877980659) throw new Error('bbox has invalid north value');
if (args.bbox[0] > args.bbox[2]) throw new Error('bbox is invalid');
if (args.bbox[1] > args.bbox[3]) throw new Error('bbox is invalid');
if (typeof args.minZoom !== 'number') throw new Error('minZoom must be a number');
if (typeof args.maxZoom !== 'number') throw new Error('maxZoom must be a number');
if (typeof args.concurrency !== 'number') args.concurrency = os.cpus().length * 25;
if (typeof callback !== 'function') callback = function() {};
if (!args.tiles && !args.grids) throw new Error('You must copy at least grids or tiles (or both)');
if (args.minZoom < 0) throw new Error('minZoom must be >= 0');
if (args.maxZoom > 22) throw new Error('maxZoom must be <= 22');
if (args.minZoom > args.maxZoom) throw new Error('maxZoom must be >= minZoom');
var action = new EventEmitter;
action.copied = 0;
action.failed = 0;
action.total = 0;
action.started = Date.now();
action.on('finished', callback);
// Precalculate the tile int bounds for each zoom level.
var bounds = {};
for (var z = args.minZoom; z <= args.maxZoom; z++) {
bounds[z] = sm.xyz(args.bbox, z);
action.total += (bounds[z].maxX - bounds[z].minX + 1) *
(bounds[z].maxY - bounds[z].minY + 1);
}
// We have twice the amount of things to copy when we copy both.
if (args.grids && args.tiles) action.total *= 2;
// Sets z, x and y to the next tile.
var z = args.minZoom;
// Start out one tile left to the starting position because we increment
// as the first action in the id() function.
var x = bounds[z].minX - 1;
var y = bounds[z].minY;
if (args.source.metatile > 1) {
var boxSize = args.source.metatile, boxLeft, boxTop, boxLeft, boxBottom;
var resetID = function() {
boxLeft = x - x % boxSize;
boxRight = boxLeft + boxSize;
boxTop = y - y % boxSize;
boxBottom = boxTop + boxSize;
}
resetID(); // Initialize.
var id = function() {
if (z > args.maxZoom) return false;
++x;
if (x >= boxRight || x > bounds[z].maxX) { // Start the next row in this metatile.
x = Math.max(boxLeft, bounds[z].minX);
y++;
}
if (y >= boxBottom || y > bounds[z].maxY) { // Start the next metatile in this row.
boxLeft += boxSize;
boxRight = boxLeft + boxSize;
x = boxLeft;
y = Math.max(boxTop, bounds[z].minY);
}
if (x > bounds[z].maxX) { // Start the next metatile row.
x = bounds[z].minX;
y = boxBottom;
resetID();
}
if (y > bounds[z].maxY) { // All rows in this zoom level are exhausted.
if (++z > args.maxZoom) return false;
x = bounds[z].minX;
y = bounds[z].minY;
resetID();
}
return true;
};
} else {
var id = function() {
if (z > args.maxZoom) return false;
if (++x > bounds[z].maxX) {
x = bounds[z].minX;
y++;
}
if (y > bounds[z].maxY) {
if (++z > args.maxZoom) return false;
x = bounds[z].minX;
y = bounds[z].minY;
}
return true;
};
}
function copy(type, z, x, y, callback) {
var get = type === 'grid' ? 'getGrid' : 'getTile';
var put = type === 'grid' ? 'putGrid' : 'putTile';
args.source[get](z, x, y, function(err, data) {
if (err) {
action.failed++;
action.emit('warning', err);
return callback();
} else {
args.sink[put](z, x, y, data, function(err) {
if (err) {
action.failed++;
action.emit('warning', err);
} else {
action.copied++;
}
callback();
});
}
});
}
var q = new Queue(function(coords, next) {
// Make sure there's something in the queue.
if (id()) q.add([z, x, y]);
Step(function() {
if (args.tiles) copy('tile', coords[0], coords[1], coords[2], this.parallel());
if (args.grids) copy('grid', coords[0], coords[1], coords[2], this.parallel());
}, next);
}, args.concurrency);
args.sink.startWriting(function(err) {
if (err) return action.emit('error', err);
// Once the queue is empty, all tiles have been copied.
q.on('empty', function() {
args.sink.stopWriting(function(err) {
if (err) {
action.emit('error', err);
} else {
action.emit('finished');
}
});
});
// Fill the queue.
for (var i = args.concurrency; i && id(); i--) {
q.add([z, x, y]);
}
});
return action;
};
{
"name" : "tilelive",
"version" : "4.3.3",
"version" : "4.4.0",
"main" : "./lib/tilelive.js",

@@ -28,3 +28,2 @@ "description" : "Frontend for various tile backends, mapnik and mbtiles",

"dependencies": {
"generic-pool": "~1.0.9",
"optimist": "~0.3.1",

@@ -44,3 +43,3 @@ "step": "~0.0.5",

"bin": {
"tilelive": "./bin/tilelive"
"tilelive-copy": "./bin/copy"
},

@@ -47,0 +46,0 @@ "engines": {

@@ -33,15 +33,11 @@ var Step = require('step');

it('should copy', function(done) {
tilelive.copy({
source: source,
sink: sink,
var scheme = tilelive.Scheme.create('scanline', {
bbox: [ -10, -10, 10, 10 ],
minZoom: 3,
maxZoom: 5,
tiles: true
}, function(err) {
source.close(function(err) {
if (err) done(err);
else sink.close(done);
});
minzoom: 3,
maxzoom: 5
});
var task = new tilelive.CopyTask(source, sink, scheme);
task.on('error', done);
task.on('finished', done);
task.start();
});

@@ -48,0 +44,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc