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

shapefile

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shapefile - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

shp/concat.js

76

dist/shapefile.js

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

// https://github.com/mbostock/shapefile Version 0.6.2. Copyright 2017 Mike Bostock.
// https://github.com/mbostock/shapefile Version 0.6.3. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.shapefile = global.shapefile || {})));
(factory((global.shapefile = {})));
}(this, (function (exports) { 'use strict';

@@ -219,3 +219,3 @@

var readMultiPoint = function(record) {
var parseMultiPoint = function(record) {
var i = 40, j, n = record.getInt32(36, true), coordinates = new Array(n);

@@ -226,11 +226,11 @@ for (j = 0; j < n; ++j, i += 16) coordinates[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true)];

var readNull = function() {
var parseNull = function() {
return null;
};
var readPoint = function(record) {
var parsePoint = function(record) {
return {type: "Point", coordinates: [record.getFloat64(4, true), record.getFloat64(12, true)]};
};
var readPolygon = function(record) {
var parsePolygon = function(record) {
var i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m), polygons = [], holes = [];

@@ -301,3 +301,3 @@ for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true);

var readPolyLine = function(record) {
var parsePolyLine = function(record) {
var i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m);

@@ -311,24 +311,50 @@ for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true);

var concat$1 = function(a, b) {
var ab = new a.constructor(a.length + b.length);
ab.set(a, 0);
ab.set(b, a.length);
return ab;
};
var shp_read = function() {
var that = this;
return that._source.slice(8).then(function(array) {
++that._index;
return that._source.slice(12).then(function(array) {
if (array == null) return {done: true, value: undefined};
var header = view(array);
return that._source.slice(header.getInt32(4, false) * 2).then(function(array) {
var record = view(array);
return {done: false, value: record.getInt32(0, true) ? that._type(record) : readNull()};
});
// If the record starts with an invalid shape type (see #36), scan ahead in
// four-byte increments to find the next valid record, identified by the
// expected index, a non-empty content length and a valid shape type.
function skip() {
return that._source.slice(4).then(function(chunk) {
if (chunk == null) return {done: true, value: undefined};
header = view(array = concat$1(array.slice(4), chunk));
return header.getInt32(0, false) !== that._index ? skip() : read();
});
}
// All records should have at least four bytes (for the record shape type),
// so an invalid content length indicates corruption.
function read() {
var length = header.getInt32(4, false) * 2 - 4, type = header.getInt32(8, true);
return length < 0 || (type && type !== that._type) ? skip() : that._source.slice(length).then(function(chunk) {
return {done: false, value: type ? that._parse(view(concat$1(array.slice(8), chunk))) : null};
});
}
return read();
});
};
var types$1 = {
0: readNull,
1: readPoint,
3: readPolyLine,
5: readPolygon,
8: readMultiPoint,
11: readPoint,
13: readPolyLine,
15: readPolygon,
18: readMultiPoint
var parsers = {
0: parseNull,
1: parsePoint,
3: parsePolyLine,
5: parsePolygon,
8: parseMultiPoint,
11: parsePoint,
13: parsePolyLine,
15: parsePolygon,
18: parseMultiPoint
};

@@ -345,5 +371,7 @@

var type = header.getInt32(32, true);
if (!(type in types$1)) throw new Error("unsupported shape type: " + type);
if (!(type in parsers)) throw new Error("unsupported shape type: " + type);
this._source = source;
this._type = types$1[type];
this._type = type;
this._index = 0;
this._parse = parsers[type];
this.bbox = [header.getFloat64(36, true), header.getFloat64(44, true), header.getFloat64(52, true), header.getFloat64(60, true)];

@@ -350,0 +378,0 @@ }

@@ -1,2 +0,2 @@

// https://github.com/mbostock/shapefile Version 0.6.2. Copyright 2017 Mike Bostock.
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.shapefile=e.shapefile||{})}(this,function(e){"use strict";function n(e){return new t(e instanceof Uint8Array?e:new Uint8Array(e))}function t(e){this._array=e}function r(e){return("function"==typeof fetch?A:U)(e)}function o(e){return"function"==typeof e.read?e:e.getReader()}function i(e,n){if(!e.length)return n;if(!n.length)return e;var t=new Uint8Array(e.length+n.length);return t.set(e),t.set(n,e.length),t}function u(e){return"function"==typeof e.slice?e:new a("function"==typeof e.read?e:e.getReader())}function a(e){this._source=e,this._array=F,this._index=0}function f(e,n,t,r){this._source=e,this._decode=n.decode.bind(n),this._recordLength=t.getUint16(10,!0),this._fields=[];for(var o=0;13!==r.getUint8(o);o+=32){for(var i=0;i<11&&0!==r.getUint8(o+i);++i);this._fields.push({name:this._decode(new Uint8Array(r.buffer,r.byteOffset+o,i)),type:String.fromCharCode(r.getUint8(o+11)),length:r.getUint8(o+16)})}}function s(){return this._source.cancel()}function c(e){if((n=e.length)<4)return!1;for(var n,t=0,r=e[n-1][1]*e[0][0]-e[n-1][0]*e[0][1];++t<n;)r+=e[t-1][1]*e[t][0]-e[t-1][0]*e[t][1];return r>=0}function l(e,n){for(var t,r=-1,o=n.length;++r<o;)if(t=h(e,n[r]))return t>0;return!1}function h(e,n){for(var t=n[0],r=n[1],o=-1,i=0,u=e.length,a=u-1;i<u;a=i++){var f=e[i],s=f[0],c=f[1],l=e[a],h=l[0],y=l[1];if(d(f,l,n))return 0;c>r!=y>r&&t<(h-s)*(r-c)/(y-c)+s&&(o=-o)}return o}function d(e,n,t){var r=t[0]-e[0],o=t[1]-e[1];if(0===r&&0===o)return!0;var i=n[0]-e[0],u=n[1]-e[1];if(0===i&&0===u)return!1;var a=(r*i+o*u)/(i*i+u*u);return!(a<0||a>1)&&(0===a||1===a||a*i===r&&a*u===o)}function y(e,n){var t=n.getInt32(32,!0);if(!(t in X))throw new Error("unsupported shape type: "+t);this._source=e,this._type=X[t],this.bbox=[n.getFloat64(36,!0),n.getFloat64(44,!0),n.getFloat64(52,!0),n.getFloat64(60,!0)]}function p(){}function g(e,n){this._shp=e,this._dbf=n,this.bbox=e.bbox}function v(e,t,i){return"string"==typeof t?(/\.dbf$/.test(t)||(t+=".dbf"),t=r(t,i)):t instanceof ArrayBuffer||t instanceof Uint8Array?t=n(t):null!=t&&(t=o(t)),"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),void 0===t&&(t=r(e.substring(0,e.length-4)+".dbf",i).catch(function(){})),e=r(e,i)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.all([e,t]).then(function(e){var n=e[0],t=e[1],r="windows-1252";return i&&null!=i.encoding&&(r=i.encoding),Q(n,t,t&&new TextDecoder(r))})}function _(e,t){return"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),e=r(e,t)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.resolve(e).then(k)}function b(e,t){var i="windows-1252";return t&&null!=t.encoding&&(i=t.encoding),i=new TextDecoder(i),"string"==typeof e?(/\.dbf$/.test(e)||(e+=".dbf"),e=r(e,t)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.resolve(e).then(function(e){return T(e,i)})}function w(e,n,t){return v(e,n,t).then(function(e){var n=[],t={type:"FeatureCollection",features:n,bbox:e.bbox};return e.read().then(function r(o){return o.done?t:(n.push(o.value),e.read().then(r))})})}var m=function(){return this._array=null,Promise.resolve()},x=function(){var e=this._array;return this._array=null,Promise.resolve(e?{done:!1,value:e}:{done:!0,value:void 0})};t.prototype.read=x,t.prototype.cancel=m;var A=function(e){return fetch(e).then(function(e){return e.body&&e.body.getReader?e.body.getReader():e.arrayBuffer().then(n)})},U=function(e){return new Promise(function(t,r){var o=new XMLHttpRequest;o.responseType="arraybuffer",o.onload=function(){t(n(o.response))},o.onerror=r,o.ontimeout=r,o.open("GET",e,!0),o.send()})},F=new Uint8Array(0),P=function(){return this._source.cancel()},I=function(){var e=this,n=e._array.subarray(e._index);return e._source.read().then(function(t){return e._array=F,e._index=0,t.done?n.length>0?{done:!1,value:n}:{done:!0,value:void 0}:{done:!1,value:i(n,t.value)}})},L=function(e){if((e|=0)<0)throw new Error("invalid length");var n=this,t=this._array.length-this._index;if(this._index+e<=this._array.length)return Promise.resolve(this._array.subarray(this._index,this._index+=e));var r=new Uint8Array(e);return r.set(this._array.subarray(this._index)),function o(){return n._source.read().then(function(i){return i.done?(n._array=F,n._index=0,t>0?r.subarray(0,t):null):t+i.value.length>=e?(n._array=i.value,n._index=e-t,r.set(i.value.subarray(0,e-t),t),r):(r.set(i.value,t),t+=i.value.length,o())})}()};a.prototype.read=I,a.prototype.slice=L,a.prototype.cancel=P;var B=function(){return this._source.cancel()},D=function(e){return!/^[nf]$/i.test(e)&&(!!/^[yt]$/i.test(e)||null)},M=function(e){return new Date(+e.substring(0,4),e.substring(4,6)-1,+e.substring(6,8))},$=function(e){return!(e=e.trim())||isNaN(e=+e)?null:e},E=function(e){return e.trim()||null},R={B:$,C:E,D:M,F:$,L:D,M:$,N:$},C=function(){var e=this,n=1;return e._source.slice(e._recordLength).then(function(t){return t&&26!==t[0]?{done:!1,value:e._fields.reduce(function(r,o){return r[o.name]=R[o.type](e._decode(t.subarray(n,n+=o.length))),r},{})}:{done:!0,value:void 0}})},S=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},T=function(e,n){return e=u(e),e.slice(32).then(function(t){var r=S(t);return e.slice(r.getUint16(8,!0)-32).then(function(t){return new f(e,n,r,S(t))})})},N=f.prototype;N.read=C,N.cancel=B;var O=function(e){var n,t=40,r=e.getInt32(36,!0),o=new Array(r);for(n=0;n<r;++n,t+=16)o[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return{type:"MultiPoint",coordinates:o}},j=function(){return null},q=function(e){return{type:"Point",coordinates:[e.getFloat64(4,!0),e.getFloat64(12,!0)]}},G=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o),a=[],f=[];for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return i.forEach(function(e,n){var t=u.slice(e,i[n+1]);c(t)?a.push([t]):f.push(t)}),f.forEach(function(e){a.some(function(n){if(l(n[0],e))return n.push(e),!0})||a.push([e])}),1===a.length?{type:"Polygon",coordinates:a[0]}:{type:"MultiPolygon",coordinates:a}},H=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o);for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return 1===r?{type:"LineString",coordinates:u}:{type:"MultiLineString",coordinates:i.map(function(e,n){return u.slice(e,i[n+1])})}},V=function(){var e=this;return e._source.slice(8).then(function(n){if(null==n)return{done:!0,value:void 0};var t=S(n);return e._source.slice(2*t.getInt32(4,!1)).then(function(n){var t=S(n);return{done:!1,value:t.getInt32(0,!0)?e._type(t):j()}})})},X={0:j,1:q,3:H,5:G,8:O,11:q,13:H,15:G,18:O},k=function(e){return e=u(e),e.slice(100).then(function(n){return new y(e,S(n))})},z=y.prototype;z.read=V,z.cancel=s;var J=function(){return Promise.all([this._dbf&&this._dbf.cancel(),this._shp.cancel()]).then(p)},K=function(){var e=this;return Promise.all([e._dbf?e._dbf.read():{value:{}},e._shp.read()]).then(function(e){var n=e[0],t=e[1];return t.done?t:{done:!1,value:{type:"Feature",properties:n.value,geometry:t.value}}})},Q=function(e,n,t){return Promise.all([k(e),n&&T(n,t)]).then(function(e){return new g(e[0],e[1])})},W=g.prototype;W.read=K,W.cancel=J,e.open=v,e.openShp=_,e.openDbf=b,e.read=w,Object.defineProperty(e,"__esModule",{value:!0})});
// https://github.com/mbostock/shapefile Version 0.6.3. Copyright 2017 Mike Bostock.
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.shapefile={})}(this,function(e){"use strict";function n(e){return new t(e instanceof Uint8Array?e:new Uint8Array(e))}function t(e){this._array=e}function r(e){return("function"==typeof fetch?v:_)(e)}function o(e){return"function"==typeof e.read?e:e.getReader()}function i(e,n){if(!e.length)return n;if(!n.length)return e;var t=new Uint8Array(e.length+n.length);return t.set(e),t.set(n,e.length),t}function u(e){return"function"==typeof e.slice?e:new a("function"==typeof e.read?e:e.getReader())}function a(e){this._source=e,this._array=b,this._index=0}function s(e,n,t,r){this._source=e,this._decode=n.decode.bind(n),this._recordLength=t.getUint16(10,!0),this._fields=[];for(var o=0;13!==r.getUint8(o);o+=32){for(var i=0;i<11&&0!==r.getUint8(o+i);++i);this._fields.push({name:this._decode(new Uint8Array(r.buffer,r.byteOffset+o,i)),type:String.fromCharCode(r.getUint8(o+11)),length:r.getUint8(o+16)})}}function f(e){if((n=e.length)<4)return!1;for(var n,t=0,r=e[n-1][1]*e[0][0]-e[n-1][0]*e[0][1];++t<n;)r+=e[t-1][1]*e[t][0]-e[t-1][0]*e[t][1];return r>=0}function c(e,n){for(var t,r=-1,o=n.length;++r<o;)if(t=l(e,n[r]))return t>0;return!1}function l(e,n){for(var t=n[0],r=n[1],o=-1,i=0,u=e.length,a=u-1;i<u;a=i++){var s=e[i],f=s[0],c=s[1],l=e[a],d=l[0],y=l[1];if(h(s,l,n))return 0;c>r!=y>r&&t<(d-f)*(r-c)/(y-c)+f&&(o=-o)}return o}function h(e,n,t){var r=t[0]-e[0],o=t[1]-e[1];if(0===r&&0===o)return!0;var i=n[0]-e[0],u=n[1]-e[1];if(0===i&&0===u)return!1;var a=(r*i+o*u)/(i*i+u*u);return!(a<0||a>1)&&(0===a||1===a||a*i===r&&a*u===o)}function d(e,n){var t=n.getInt32(32,!0);if(!(t in D))throw new Error("unsupported shape type: "+t);this._source=e,this._type=t,this._index=0,this._parse=D[t],this.bbox=[n.getFloat64(36,!0),n.getFloat64(44,!0),n.getFloat64(52,!0),n.getFloat64(60,!0)]}function y(){}function g(e,n){this._shp=e,this._dbf=n,this.bbox=e.bbox}function p(e,t,i){return"string"==typeof t?(/\.dbf$/.test(t)||(t+=".dbf"),t=r(t,i)):t instanceof ArrayBuffer||t instanceof Uint8Array?t=n(t):null!=t&&(t=o(t)),"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),void 0===t&&(t=r(e.substring(0,e.length-4)+".dbf",i).catch(function(){})),e=r(e,i)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.all([e,t]).then(function(e){var n=e[0],t=e[1],r="windows-1252";return i&&null!=i.encoding&&(r=i.encoding),E(n,t,t&&new TextDecoder(r))})}t.prototype.read=function(){var e=this._array;return this._array=null,Promise.resolve(e?{done:!1,value:e}:{done:!0,value:void 0})},t.prototype.cancel=function(){return this._array=null,Promise.resolve()};var v=function(e){return fetch(e).then(function(e){return e.body&&e.body.getReader?e.body.getReader():e.arrayBuffer().then(n)})},_=function(e){return new Promise(function(t,r){var o=new XMLHttpRequest;o.responseType="arraybuffer",o.onload=function(){t(n(o.response))},o.onerror=r,o.ontimeout=r,o.open("GET",e,!0),o.send()})},b=new Uint8Array(0);a.prototype.read=function(){var e=this,n=e._array.subarray(e._index);return e._source.read().then(function(t){return e._array=b,e._index=0,t.done?n.length>0?{done:!1,value:n}:{done:!0,value:void 0}:{done:!1,value:i(n,t.value)}})},a.prototype.slice=function(e){if((e|=0)<0)throw new Error("invalid length");var n=this,t=this._array.length-this._index;if(this._index+e<=this._array.length)return Promise.resolve(this._array.subarray(this._index,this._index+=e));var r=new Uint8Array(e);return r.set(this._array.subarray(this._index)),function o(){return n._source.read().then(function(i){return i.done?(n._array=b,n._index=0,t>0?r.subarray(0,t):null):t+i.value.length>=e?(n._array=i.value,n._index=e-t,r.set(i.value.subarray(0,e-t),t),r):(r.set(i.value,t),t+=i.value.length,o())})}()},a.prototype.cancel=function(){return this._source.cancel()};var w=function(e){return!(e=e.trim())||isNaN(e=+e)?null:e},x={B:w,C:function(e){return e.trim()||null},D:function(e){return new Date(+e.substring(0,4),e.substring(4,6)-1,+e.substring(6,8))},F:w,L:function(e){return!/^[nf]$/i.test(e)&&(!!/^[yt]$/i.test(e)||null)},M:w,N:w},m=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},A=function(e,n){return(e=u(e)).slice(32).then(function(t){var r=m(t);return e.slice(r.getUint16(8,!0)-32).then(function(t){return new s(e,n,r,m(t))})})},U=s.prototype;U.read=function(){var e=this,n=1;return e._source.slice(e._recordLength).then(function(t){return t&&26!==t[0]?{done:!1,value:e._fields.reduce(function(r,o){return r[o.name]=x[o.type](e._decode(t.subarray(n,n+=o.length))),r},{})}:{done:!0,value:void 0}})},U.cancel=function(){return this._source.cancel()};var F=function(e){var n,t=40,r=e.getInt32(36,!0),o=new Array(r);for(n=0;n<r;++n,t+=16)o[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return{type:"MultiPoint",coordinates:o}},P=function(e){return{type:"Point",coordinates:[e.getFloat64(4,!0),e.getFloat64(12,!0)]}},I=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o),a=[],s=[];for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return i.forEach(function(e,n){var t=u.slice(e,i[n+1]);f(t)?a.push([t]):s.push(t)}),s.forEach(function(e){a.some(function(n){if(c(n[0],e))return n.push(e),!0})||a.push([e])}),1===a.length?{type:"Polygon",coordinates:a[0]}:{type:"MultiPolygon",coordinates:a}},L=function(e){var n,t=44,r=e.getInt32(36,!0),o=e.getInt32(40,!0),i=new Array(r),u=new Array(o);for(n=0;n<r;++n,t+=4)i[n]=e.getInt32(t,!0);for(n=0;n<o;++n,t+=16)u[n]=[e.getFloat64(t,!0),e.getFloat64(t+8,!0)];return 1===r?{type:"LineString",coordinates:u}:{type:"MultiLineString",coordinates:i.map(function(e,n){return u.slice(e,i[n+1])})}},B=function(e,n){var t=new e.constructor(e.length+n.length);return t.set(e,0),t.set(n,e.length),t},D={0:function(){return null},1:P,3:L,5:I,8:F,11:P,13:L,15:I,18:F},M=function(e){return(e=u(e)).slice(100).then(function(n){return new d(e,m(n))})},$=d.prototype;$.read=function(){var e=this;return++e._index,e._source.slice(12).then(function(n){function t(){return e._source.slice(4).then(function(i){return null==i?{done:!0,value:void 0}:(o=m(n=B(n.slice(4),i))).getInt32(0,!1)!==e._index?t():r()})}function r(){var r=2*o.getInt32(4,!1)-4,i=o.getInt32(8,!0);return r<0||i&&i!==e._type?t():e._source.slice(r).then(function(t){return{done:!1,value:i?e._parse(m(B(n.slice(8),t))):null}})}if(null==n)return{done:!0,value:void 0};var o=m(n);return r()})},$.cancel=function(){return this._source.cancel()};var E=function(e,n,t){return Promise.all([M(e),n&&A(n,t)]).then(function(e){return new g(e[0],e[1])})},R=g.prototype;R.read=function(){var e=this;return Promise.all([e._dbf?e._dbf.read():{value:{}},e._shp.read()]).then(function(e){var n=e[0],t=e[1];return t.done?t:{done:!1,value:{type:"Feature",properties:n.value,geometry:t.value}}})},R.cancel=function(){return Promise.all([this._dbf&&this._dbf.cancel(),this._shp.cancel()]).then(y)},e.open=p,e.openShp=function(e,t){return"string"==typeof e?(/\.shp$/.test(e)||(e+=".shp"),e=r(e,t)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.resolve(e).then(M)},e.openDbf=function(e,t){var i="windows-1252";return t&&null!=t.encoding&&(i=t.encoding),i=new TextDecoder(i),"string"==typeof e?(/\.dbf$/.test(e)||(e+=".dbf"),e=r(e,t)):e=e instanceof ArrayBuffer||e instanceof Uint8Array?n(e):o(e),Promise.resolve(e).then(function(e){return A(e,i)})},e.read=function(e,n,t){return p(e,n,t).then(function(e){var n=[],t={type:"FeatureCollection",features:n,bbox:e.bbox};return e.read().then(function r(o){return o.done?t:(n.push(o.value),e.read().then(r))})})},Object.defineProperty(e,"__esModule",{value:!0})});

@@ -93,3 +93,3 @@ 'use strict';

var readMultiPoint = function(record) {
var parseMultiPoint = function(record) {
var i = 40, j, n = record.getInt32(36, true), coordinates = new Array(n);

@@ -100,11 +100,11 @@ for (j = 0; j < n; ++j, i += 16) coordinates[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true)];

var readNull = function() {
var parseNull = function() {
return null;
};
var readPoint = function(record) {
var parsePoint = function(record) {
return {type: "Point", coordinates: [record.getFloat64(4, true), record.getFloat64(12, true)]};
};
var readPolygon = function(record) {
var parsePolygon = function(record) {
var i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m), polygons = [], holes = [];

@@ -175,3 +175,3 @@ for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true);

var readPolyLine = function(record) {
var parsePolyLine = function(record) {
var i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m);

@@ -185,24 +185,50 @@ for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true);

var concat = function(a, b) {
var ab = new a.constructor(a.length + b.length);
ab.set(a, 0);
ab.set(b, a.length);
return ab;
};
var shp_read = function() {
var that = this;
return that._source.slice(8).then(function(array$$1) {
++that._index;
return that._source.slice(12).then(function(array$$1) {
if (array$$1 == null) return {done: true, value: undefined};
var header = view(array$$1);
return that._source.slice(header.getInt32(4, false) * 2).then(function(array$$1) {
var record = view(array$$1);
return {done: false, value: record.getInt32(0, true) ? that._type(record) : readNull()};
});
// If the record starts with an invalid shape type (see #36), scan ahead in
// four-byte increments to find the next valid record, identified by the
// expected index, a non-empty content length and a valid shape type.
function skip() {
return that._source.slice(4).then(function(chunk) {
if (chunk == null) return {done: true, value: undefined};
header = view(array$$1 = concat(array$$1.slice(4), chunk));
return header.getInt32(0, false) !== that._index ? skip() : read();
});
}
// All records should have at least four bytes (for the record shape type),
// so an invalid content length indicates corruption.
function read() {
var length = header.getInt32(4, false) * 2 - 4, type = header.getInt32(8, true);
return length < 0 || (type && type !== that._type) ? skip() : that._source.slice(length).then(function(chunk) {
return {done: false, value: type ? that._parse(view(concat(array$$1.slice(8), chunk))) : null};
});
}
return read();
});
};
var types$1 = {
0: readNull,
1: readPoint,
3: readPolyLine,
5: readPolygon,
8: readMultiPoint,
11: readPoint,
13: readPolyLine,
15: readPolygon,
18: readMultiPoint
var parsers = {
0: parseNull,
1: parsePoint,
3: parsePolyLine,
5: parsePolygon,
8: parseMultiPoint,
11: parsePoint,
13: parsePolyLine,
15: parsePolygon,
18: parseMultiPoint
};

@@ -219,5 +245,7 @@

var type = header.getInt32(32, true);
if (!(type in types$1)) throw new Error("unsupported shape type: " + type);
if (!(type in parsers)) throw new Error("unsupported shape type: " + type);
this._source = source;
this._type = types$1[type];
this._type = type;
this._index = 0;
this._parse = parsers[type];
this.bbox = [header.getFloat64(36, true), header.getFloat64(44, true), header.getFloat64(52, true), header.getFloat64(60, true)];

@@ -224,0 +252,0 @@ }

{
"name": "shapefile",
"version": "0.6.2",
"version": "0.6.3",
"description": "An implementation of the shapefile (.shp) spatial data format.",

@@ -29,3 +29,3 @@ "keywords": [

"test": "tape 'test/**/*-test.js'",
"prepublish": "npm run test && rollup -c --banner \"$(preamble)\" -f umd -n shapefile -o dist/shapefile.js -- index.js && uglifyjs --preamble \"$(preamble)\" -o dist/shapefile.min.js -cm -- dist/shapefile.js",
"prepublish": "npm run test && rollup -c --banner \"$(preamble)\" -f umd -n shapefile -o dist/shapefile.js -- index.js && uglifyjs -b beautify=false,preamble=\"'$(preamble)'\" -o dist/shapefile.min.js -cm -- dist/shapefile.js",
"postpublish": "git push && git push --tags && zip -j dist/shapefile.zip -- LICENSE.txt README.md dist/shapefile.js dist/shapefile.min.js"

@@ -39,11 +39,11 @@ },

"stream-source": "0.3",
"text-encoding": "0.6.1"
"text-encoding": "^0.6.4"
},
"devDependencies": {
"package-preamble": "0.0",
"rollup": "0.41",
"rollup-plugin-node-resolve": "2",
"package-preamble": "0.1",
"rollup": "0.45",
"rollup-plugin-node-resolve": "3",
"tape": "4",
"uglify-js": "2"
"uglify-js": "3"
}
}
import slice from "slice-source";
import view from "../view";
import shp_cancel from "./cancel";
import readMultiPoint from "./multipoint";
import readNull from "./null";
import readPoint from "./point";
import readPolygon from "./polygon";
import readPolyLine from "./polyline";
import parseMultiPoint from "./multipoint";
import parseNull from "./null";
import parsePoint from "./point";
import parsePolygon from "./polygon";
import parsePolyLine from "./polyline";
import shp_read from "./read";
var types = {
0: readNull,
1: readPoint,
3: readPolyLine,
5: readPolygon,
8: readMultiPoint,
11: readPoint,
13: readPolyLine,
15: readPolygon,
18: readMultiPoint
var parsers = {
0: parseNull,
1: parsePoint,
3: parsePolyLine,
5: parsePolygon,
8: parseMultiPoint,
11: parsePoint,
13: parsePolyLine,
15: parsePolygon,
18: parseMultiPoint
};

@@ -32,5 +32,7 @@

var type = header.getInt32(32, true);
if (!(type in types)) throw new Error("unsupported shape type: " + type);
if (!(type in parsers)) throw new Error("unsupported shape type: " + type);
this._source = source;
this._type = types[type];
this._type = type;
this._index = 0;
this._parse = parsers[type];
this.bbox = [header.getFloat64(36, true), header.getFloat64(44, true), header.getFloat64(52, true), header.getFloat64(60, true)];

@@ -37,0 +39,0 @@ }

@@ -0,14 +1,33 @@

import concat from "./concat";
import view from "../view";
import readNull from "./null";
export default function() {
var that = this;
return that._source.slice(8).then(function(array) {
++that._index;
return that._source.slice(12).then(function(array) {
if (array == null) return {done: true, value: undefined};
var header = view(array);
return that._source.slice(header.getInt32(4, false) * 2).then(function(array) {
var record = view(array);
return {done: false, value: record.getInt32(0, true) ? that._type(record) : readNull()};
});
// If the record starts with an invalid shape type (see #36), scan ahead in
// four-byte increments to find the next valid record, identified by the
// expected index, a non-empty content length and a valid shape type.
function skip() {
return that._source.slice(4).then(function(chunk) {
if (chunk == null) return {done: true, value: undefined};
header = view(array = concat(array.slice(4), chunk));
return header.getInt32(0, false) !== that._index ? skip() : read();
});
}
// All records should have at least four bytes (for the record shape type),
// so an invalid content length indicates corruption.
function read() {
var length = header.getInt32(4, false) * 2 - 4, type = header.getInt32(8, true);
return length < 0 || (type && type !== that._type) ? skip() : that._source.slice(length).then(function(chunk) {
return {done: false, value: type ? that._parse(view(concat(array.slice(8), chunk))) : null};
});
}
return read();
});
}
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