Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tilelive

Package Overview
Dependencies
Maintainers
21
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 5.1.2 to 5.2.0

lib/stream-deserialize.js

78

lib/stream-util.js
var concurrency = Math.ceil(require('os').cpus().length * 16);
var util = require('util');

@@ -6,3 +7,4 @@ module.exports = {};

module.exports.Info = Info;
module.exports.Stats = Stats;;
module.exports.DeserializationError = DeserializationError;
module.exports.Stats = Stats;
module.exports.addChildren = addChildren;

@@ -14,8 +16,17 @@ module.exports.sumChildren = sumChildren;

module.exports.setConcurrency = setConcurrency;
module.exports.serialize = serialize;
module.exports.deserialize = deserialize;
module.exports.serialHeader = 'JSONBREAKFASTTIME';
function DeserializationError(msg) {
this.message = msg;
this.name = 'DeserializationError';
}
util.inherits(DeserializationError, Error);
function Tile(z,x,y,buffer) {
this.z = z;
this.x = x;
this.y = y;
this.buffer = buffer;
this.z = isNaN(z) ? undefined : Number(z);
this.x = isNaN(x) ? undefined : Number(x);
this.y = isNaN(y) ? undefined : Number(y);
this.buffer = buffer instanceof Buffer ? buffer : undefined;
return this;

@@ -29,2 +40,58 @@ }

function serialize(obj) {
if (obj instanceof Tile) return serializeTile(obj);
if (obj instanceof Info) return serializeInfo(obj);
return '';
}
function deserialize(data) {
if (data.indexOf('{"z":') === 0) return deserializeTile(data);
if (data.indexOf('{') === 0) return deserializeInfo(data);
throw new DeserializationError('Invalid data');
}
function serializeTile(tile) {
var obj = {
z: isNaN(tile.z) ? null : Number(tile.z),
x: isNaN(tile.x) ? null : Number(tile.x),
y: isNaN(tile.y) ? null : Number(tile.y),
buffer: tile.buffer instanceof Buffer ? tile.buffer.toString('base64') : null
};
return JSON.stringify(obj);
}
function serializeInfo(info) {
return JSON.stringify(info);
}
function deserializeTile(data) {
var obj, buf;
try { obj = JSON.parse(data); }
catch(err) { throw new DeserializationError('Could not parse data'); }
if (!obj.hasOwnProperty('z') ||
!obj.hasOwnProperty('x') ||
!obj.hasOwnProperty('y') ||
!obj.hasOwnProperty('buffer')) {
throw new DeserializationError('Invalid data');
}
if (typeof obj.buffer === 'string' || typeof obj.buffer === 'number') {
buf = new Buffer(obj.buffer, 'base64');
} else {
throw new DeserializationError('Invalid buffer');
}
return new Tile(obj.z, obj.x, obj.y, buf);
}
function deserializeInfo(data) {
try { obj = JSON.parse(data); }
catch(err) { throw new DeserializationError('Could not parse data'); }
return new Info(obj);
}
function Stats() {

@@ -138,2 +205,1 @@ this.ops = 0;

}

@@ -322,1 +322,6 @@ var tilelive = exports;

tilelive.streamTypes.list = require('./stream-list');
var Serialize = require('./stream-serialize');
var Deserialize = require('./stream-deserialize');
tilelive.serialize = function() { return new Serialize(); };
tilelive.deserialize = function() { return new Deserialize(); };

2

package.json
{
"name": "tilelive",
"version": "5.1.2",
"version": "5.2.0",
"main": "./lib/tilelive.js",

@@ -5,0 +5,0 @@ "description": "API for various map tile backends",

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