sigfile
Version:
Utilities to reading signal data from files
51 lines • 13.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.bluefile=e():t.bluefile=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r.r(e),r.d(e,"BlueHeader",(function(){return A})),r.d(e,"BlueFileReader",(function(){return w}));var i=function(){function t(e){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e instanceof ArrayBuffer||"number"!=typeof e?(this.buffer=e,this.u8=new Uint8Array(e)):(this.buffer=new ArrayBuffer(e/8),this.u8=new Uint8Array(this.buffer)),new Proxy(this,{get:function(t,e){return t[e]?t[e]:t.getBit(e)},set:function(t,e,r){var n=parseInt(e);return!isNaN(n)&&(t.setBit(e,r),!0)}})}var e,r,i;return e=t,(r=[{key:"set",value:function(t){this.setArray(t)}},{key:"getBit",value:function(t){return this.u8[t>>3]>>7-(7&t)&1}},{key:"setBit",value:function(t,e){var r=7&t;e?this.u8[t>>3]|=128>>r:this.u8[t>>3]&=~(128>>r)}},{key:"setArray",value:function(t){for(var e=t.length,r=0;r<e;r++)this.setBit(r,t[r])}},{key:"subarray",value:function(t,e){var r=[];t=(t=t||0)<0?0:t,e=(e=e||this.length)>this.length?this.length:e;for(var n=t;n<e;n++)r.push(this.getBit(n));return r}},{key:"length",get:function(){return 8*this.u8.byteLength}}])&&n(e.prototype,r),i&&n(e,i),t}();function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){var r=new Uint8Array(t);return void 0===s._applySupportsTypedArray&&(s._applySupportsTypedArray=void 0!==e?e:function(){try{var t=new Uint8Array(new ArrayBuffer(4));if(t[0]=66,t[1]=76,t[2]=85,t[3]=69,"BLUE"!==String.fromCharCode.apply(null,t))return!1}catch(t){return!1}return!0}()),s._applySupportsTypedArray?String.fromCharCode.apply(null,r):r.reduce((function(t,e){return t+String.fromCharCode(e)}),"")}function u(t){return t>=0&&t<31?1<<t:u[t]||(u[t]=Math.pow(2,t))}function l(t){var e=document.createElement("a");return e.href=t,{source:t,protocol:e.protocol.replace(":",""),host:e.hostname,port:e.port,query:e.search,params:function(){for(var t={},r=e.search.replace(/^\?/,"").split("&"),n=r.length,i=0;i<n;i++)if(r[i]){var a=r[i].split("=");t[a[0]]=a[1]}return t}(),file:(e.pathname.match(/\/([^/?#]+)$/i)||[null,""])[1],hash:e.hash.replace("#",""),path:e.pathname.replace(/^([^/])/,"/$1"),relative:(e.href.match(/tps?:\/\/[^/]+(.+)/)||[null,""])[1],segments:e.pathname.replace(/^\//,"").split("/")}}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var c=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.header_class=e,this.options=r}var e,r,n;return e=t,(r=[{key:"_read",value:function(t,e,r){var n=this,i=new FileReader,a=void 0===t.webkitSlice?"slice":"webkitSlice",o=r?t[a](0,512):t;i.onloadend=function(t){return function(r){if(r.target.error)e(null);else{var a=i.result,o=new n.header_class(a,n.options);o.file=t,o.file_name=t.name,e(o)}}}(t),i.readAsArrayBuffer(o)}},{key:"readheader",value:function(t,e){this._read(t,e,!0)}},{key:"read",value:function(t,e){this._read(t,e,!1)}},{key:"read_http",value:function(t,e){var r=this,n=new XMLHttpRequest;return n.open("GET",t,!0),n.responseType="arraybuffer",n.overrideMimeType("text/plain; charset=x-user-defined"),n.onload=function(i){if(4!==n.readyState||200!==n.status&&0!==n.status)e(null);else{var a=null;if(n.response){a=n.response;var o=new r.header_class(a,r.options),s=l(t);o.file_name=s.file,e(o)}else n.responseText&&function(t,e,r){r=r||1024;var n=0,i=new ArrayBuffer(t.length),a=new Uint8Array(i);setTimeout((function o(){for(var s=n+r;n<s;n++)a[n]=255&t.charCodeAt(n);n>=t.length?e(i):setTimeout(o,0)}),0)}(n.responseText,(function(n){var i=new r.header_class(n,r.options),a=l(t);i.file_name=a.file,e(i)}))}},n.onerror=function(t){e(null)},n.send(null),n}}])&&f(e.prototype,r),n&&f(e,n),t}();function h(t,e){return(h=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function p(t,e){return!e||"object"!==b(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function y(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function b(t){return(b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function v(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}
/**
* @license apache-2.0
* @file bluefile.src
* Copyright (c) 2012-2020, LGS Innovations Inc., All rights reserved.
*
* This file is part of SigFile.
*
* Licensed to the LGS Innovations (LGS) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. LGS licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/var A=function(){function t(e,r){if(v(this,t),void 0===r&&(r={}),this.options=Object.assign({ext_header_type:"dict"},r),this.buf=e,null!=this.buf){this.setHeader();var n=this.data_start,i=this.data_start+this.data_size;this.setData(this.buf,n,i,this.littleEndianData)}}var e,r,n;return e=t,(r=[{key:"setHeader",value:function(){var t=new DataView(this.buf);this.version=s(this.buf.slice(0,4)),this.headrep=s(this.buf.slice(4,8)),this.datarep=s(this.buf.slice(8,12));var e="EEEI"===this.headrep;this.littleEndianData="EEEI"===this.datarep,this.ext_start=t.getInt32(24,e),this.ext_size=t.getInt32(28,e),this.type=t.getUint32(48,e),this.class=this.type/1e3,this.format=s(this.buf.slice(52,54)),this.timecode=t.getFloat64(56,e),1===this.class?(this.xstart=t.getFloat64(256,e),this.xdelta=t.getFloat64(264,e),this.xunits=t.getInt32(272,e),this.yunits=t.getInt32(296,e),this.subsize=1):2===this.class&&(this.xstart=t.getFloat64(256,e),this.xdelta=t.getFloat64(264,e),this.xunits=t.getInt32(272,e),this.subsize=t.getInt32(276,e),this.ystart=t.getFloat64(280,e),this.ydelta=t.getFloat64(288,e),this.yunits=t.getInt32(296,e)),this.data_start=t.getFloat64(32,e),this.data_size=t.getFloat64(40,e),this.ext_size&&(this.ext_header=this.unpack_keywords(this.buf,this.ext_size,512*this.ext_start,e))}},{key:"setData",value:function(e,r,n,i){void 0===i&&(i="LE"===t.ARRAY_BUFFER_ENDIANNESS),this.spa=t._SPA[this.format[0]],this.bps=t._BPS[this.format[1]],this.bpa=this.spa*this.bps,1===this.class?this.ape=1:2===this.class&&(this.ape=this.subsize),this.bpe=this.ape*this.bpa;var a="LE"===t.ARRAY_BUFFER_ENDIANNESS,o="BE"===t.ARRAY_BUFFER_ENDIANNESS;if(a&&!i||o&&this.littleEndianData)throw"Not supported ".concat(t.ARRAY_BUFFER_ENDIANNESS," ").concat(i);if(e){if(r&&n){var s=(n-r)/this.bps;this.dview=this.createArray(e,r,s)}else this.dview=this.createArray(e);this.size=this.dview.length/(this.spa*this.ape)}else this.dview=this.createArray(null,null,this.size)}},{key:"unpack_keywords",value:function(e,r,n,i){var a,o,u,l,f,c,h,p,y,d=[],v={},g={},_=0;e=e.slice(n,e.byteLength);var A=new DataView(e);for(e=s(e);_<r;){if(y=_+8,a=A.getUint32(_,i),o=A.getInt16(_+4,i),u=A.getInt8(_+6),l=e.slice(_+7,_+8),p=y+(h=a-o),f=e.slice(p,p+u),"A"===l)c=e.slice(y,y+h);else{if(!t._XM_TO_DATAVIEW[l])throw"Unsupported keyword format ".concat(l," for tag ").concat(f);var w=t._XM_TO_DATAVIEW[l];c="string"==typeof w?A[w](y,i):w(A,y,i)}void 0===v[f]?v[f]=1:(v[f]++,f=""+f+v[f]),g[f]=c,d.push({tag:f,value:c}),_+=a}var m=["dict","json",{},"XMTable","JSON","DICT"],S=this.options.ext_header_type;if("object"===b(S)&&null!==S&&0===Object.keys(S).length&&S.constructor===Object)return g;for(var E in m)if(m[E]===S)return g;return d}},{key:"createArray",value:function(e,r,n){var i,a=t._XM_TO_TYPEDARRAY[this.format[1]];if(void 0===a)throw"unknown format ".concat(this.format[1]);if(void 0===r&&(r=0),void 0===n&&(n=e.length||e.byteLength/t._BPS[this.format[1]]),e)if(Array.isArray(e)&&Array.isArray(e[0]))i=new a(e=[].concat.apply([],e),r,n=e.length*e[0].length);else if(Array.isArray(e)&&ArrayBuffer.isView(e[0])){i=new a(n=e.length*e[0].length);for(var o=0;o<e.length;++o)i.set(e[o],o*e[0].length)}else i=new a(e,r,n);else i=new a(n);return i}}])&&g(e.prototype,r),n&&g(e,n),t}();_(A,"ARRAY_BUFFER_ENDIANNESS",
/**
* @license apache-2.0
* @file util.src
* Copyright (c) 2012-2020, LGS Innovations Inc., All rights reserved.
*
* This file is part of SigFile.
*
* Licensed to the LGS Innovations (LGS) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. LGS licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
function(){var t=new ArrayBuffer(4),e=new Uint32Array(t),r=new Uint8Array(t);if(e[0]=3735928559,239===r[0])return"LE";if(222===r[0])return"BE";throw new Error("unknown endianness")}()),_(A,"_SPA",{S:1,C:2,V:3,Q:4,M:9,X:10,T:16,U:1,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9}),_(A,"_BPS",{P:.125,A:1,O:1,B:1,I:2,L:4,X:8,F:4,D:8}),_(A,"_XM_TO_TYPEDARRAY",{P:i,A:null,O:Uint8Array,B:Int8Array,I:Int16Array,L:Int32Array,X:null,F:Float32Array,D:Float64Array}),_(A,"_XM_TO_DATAVIEW",{P:null,A:null,O:"getUint8",B:"getInt8",I:"getInt16",L:"getInt32",X:function(t,e,r){var n=Math.pow(2,53),i=a(r?[4,0]:[0,4],2),o=i[0],s=i[1],l=t.getInt32(e+o,r),f=t.getInt32(e+s,r)+u(32)*l;return f>=n?(console.warn("Int is bigger than JS can represent."),1/0):f},F:"getFloat32",D:"getFloat64"});var w=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&h(t,e)}(n,t);var e,r=(e=n,function(){var t,r=d(e);if(y()){var n=d(this).constructor;t=Reflect.construct(r,arguments,n)}else t=r.apply(this,arguments);return p(this,t)});function n(t){return v(this,n),r.call(this,A,t)}return n}(c)}])}));
//# sourceMappingURL=bluefile.js.map