UNPKG

sigfile

Version:

Utilities to reading signal data from files

51 lines 12.6 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.matfile=t():e.matfile=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw a}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}(e,t)||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 i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t){var n=new Uint8Array(e);return void 0===a._applySupportsTypedArray&&(a._applySupportsTypedArray=void 0!==t?t:function(){try{var e=new Uint8Array(new ArrayBuffer(4));if(e[0]=66,e[1]=76,e[2]=85,e[3]=69,"BLUE"!==String.fromCharCode.apply(null,e))return!1}catch(e){return!1}return!0}()),a._applySupportsTypedArray?String.fromCharCode.apply(null,n):n.reduce((function(e,t){return e+String.fromCharCode(t)}),"")}function o(e){return e>=0&&e<31?1<<e:o[e]||(o[e]=Math.pow(2,e))}function s(e){var t=document.createElement("a");return t.href=e,{source:e,protocol:t.protocol.replace(":",""),host:t.hostname,port:t.port,query:t.search,params:function(){for(var e={},n=t.search.replace(/^\?/,"").split("&"),r=n.length,i=0;i<r;i++)if(n[i]){var a=n[i].split("=");e[a[0]]=a[1]}return e}(),file:(t.pathname.match(/\/([^/?#]+)$/i)||[null,""])[1],hash:t.hash.replace("#",""),path:t.pathname.replace(/^([^/])/,"/$1"),relative:(t.href.match(/tps?:\/\/[^/]+(.+)/)||[null,""])[1],segments:t.pathname.replace(/^\//,"").split("/")}}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.r(t),n.d(t,"MatHeader",(function(){return v})),n.d(t,"MatFileReader",(function(){return b}));var f=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.header_class=t,this.options=n}var t,n,r;return t=e,(n=[{key:"_read",value:function(e,t,n){var r=this,i=new FileReader,a=void 0===e.webkitSlice?"slice":"webkitSlice",o=n?e[a](0,512):e;i.onloadend=function(e){return function(n){if(n.target.error)t(null);else{var a=i.result,o=new r.header_class(a,r.options);o.file=e,o.file_name=e.name,t(o)}}}(e),i.readAsArrayBuffer(o)}},{key:"readheader",value:function(e,t){this._read(e,t,!0)}},{key:"read",value:function(e,t){this._read(e,t,!1)}},{key:"read_http",value:function(e,t){var n=this,r=new XMLHttpRequest;return r.open("GET",e,!0),r.responseType="arraybuffer",r.overrideMimeType("text/plain; charset=x-user-defined"),r.onload=function(i){if(4!==r.readyState||200!==r.status&&0!==r.status)t(null);else{var a=null;if(r.response){a=r.response;var o=new n.header_class(a,n.options),u=s(e);o.file_name=u.file,t(o)}else r.responseText&&function(e,t,n){n=n||1024;var r=0,i=new ArrayBuffer(e.length),a=new Uint8Array(i);setTimeout((function o(){for(var s=r+n;r<s;r++)a[r]=255&e.charCodeAt(r);r>=e.length?t(i):setTimeout(o,0)}),0)}(r.responseText,(function(r){var i=new n.header_class(r,n.options),a=s(e);i.file_name=a.file,t(i)}))}},r.onerror=function(e){t(null)},r.send(null),r}}])&&u(t.prototype,n),r&&u(t,r),e}();function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e,t){return!t||"object"!==l(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}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(e){return!1}}function m(e){return(m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function T(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e} /** * @license * File: matfile.src * Copyright (c) 2012-2017, LGS Innovations Inc., All rights reserved. * * This file is part of SigPlot. * * 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 v=function(){function e(t){if(h(this,e),this.file=null,this.file_name=null,this.buf=t,null!=this.buf){var n=new DataView(this.buf);this.headerStr=a(this.buf.slice(e.headerTextBegin-1,e.headerTextEnd)),this.datarep=a(this.buf.slice(e.endianCharsBegin-1,e.endianCharsEnd));var r="IM"===this.datarep,i="IM"===this.datarep;this.headerList=this.headerStr.split(",").map((function(e){return e.trim()})),this.matfile=this.headerList[0],this.platform=this.headerList[1],this.createdOn=this.headerList[2],this.subsystemOffset=a(this.buf.slice(e.subsysOffsetBegin-1,e.subsysOffsetEnd)),this.version=n.getUint16(e.versionOffsetBegin-1,r),this.versionName=e.versionNames[this.version],this.dataType=n.getUint32(e.firstDataTypeOffsetBegin-1,r),this.dataTypeName=e.dataTypeNames[this.dataType].name,this.arraySize=n.getUint32(e.numBytesOffsetBegin-1,r);e.numBytesOffsetEnd;var o=e.numBytesOffsetEnd+1,s=n.getUint32(o-1,r),u=e.dataTypeNames[s].name,f=e.dataTypeNames[s].size;o+=4;this.getDataWithType(n,u,o-1,i);o+=f;var l=this.getDataWithType(n,u,o-1,i);o+=f;var c=15&l;e.arrayClassNames[c];o+=f;var p=n.getUint32(o-1,i);o+=4;var y=e.dataTypeNames[p].name,m=e.dataTypeNames[p].size;n.getUint32(o-1,i);o+=4;var d=this.getDataWithType(n,y,o-1,i);o+=m,d>1&&console.warn("Only 1D arrays are currently supported.");this.getDataWithType(n,y,o-1,i);o+=f;var T=n.getUint32(o-1,i);o+=4;var v=0,b=!1;T>15&&(T&=255,b=!0,v=n.getUint16(o-5,i));var g=e.dataTypeNames[T].name;e.dataTypeNames[T].size;b||(v=this.getDataWithType(n,g,o-1,i),o+=4),o+=v+(b?(4-v%4)%4:(8-v%8)%8),this.setData(this.buf,n,o,i)}}var t,n,r;return t=e,(n=[{key:"createArray",value:function(t,n,r,i){var a=e._MAT_TO_TYPEDARRAY[i];if(void 0===a)throw"unknown type ".concat(i);return void 0===n&&(n=0),void 0===r&&(r=t.length),new a(t,n,r)}},{key:"getDataWithType",value:function(t,n,r,i){var a=e._MAT_TO_DATAVIEW[n];if(void 0===a)throw"Type name ".concat(n," is not supported");return t[a](r,i)}},{key:"setData",value:function(t,n,r,i){var a,o=n.getUint32(r-1,i),s=!1;o>15?(o&=255,s=!0,a=n.getUint16(r+1,2,i)):r+=4;var u=e.dataTypeNames[o].name,f=e.dataTypeNames[o].size;s||(a=n.getUint32(r-1,i),s=!1),r+=4,this.dview=this.createArray(t,r-1,a/f,u)}}])&&d(t.prototype,n),r&&d(t,r),e}();T(v,"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 e=new ArrayBuffer(4),t=new Uint32Array(e),n=new Uint8Array(e);if(t[0]=3735928559,239===n[0])return"LE";if(222===n[0])return"BE";throw new Error("unknown endianness")}()),T(v,"versionNames",{256:"MAT-file"}),T(v,"_MAT_TO_TYPEDARRAY",{miINT8:Int8Array,miUINT8:Uint8Array,miInt16:Int16Array,miUINT16:Uint16Array,miINT32:Int32Array,miUINT32:Uint32Array,miDOUBLE:Float64Array}),T(v,"_MAT_TO_DATAVIEW",{miINT8:"getInt8",miUINT8:"getUint8",miINT16:"getInt16",miUINT16:"getUint16",miINT32:"getInt32",miUINT32:"getUint32",miSINGLE:"getFloat32",miDOUBLE:"getFloat64",miINT64:function(e,t,n){var i=Math.pow(2,53),a=r(n?[4,0]:[0,4],2),s=a[0],u=a[1],f=e.getInt32(t+s,n),l=e.getInt32(t+u,n)+o(32)*f;return l>=i?(console.warn("Int is bigger than JS can represent."),1/0):l}}),T(v,"dataTypeNames",{1:{name:"miINT8",size:1},2:{name:"miUINT8",size:1},3:{name:"miINT16",size:2},4:{name:"miUINT16",size:2},5:{name:"miINT32",size:4},6:{name:"miUINT32",size:4},7:{name:"miSINGLE",size:4},9:{name:"miDOUBLE",size:8},12:{name:"miINT64",size:8},13:{name:"miUINT64",size:8},14:{name:"miMATRIX",size:null},15:{name:"miCOMPRESSED",size:null},16:{name:"miUTF8",size:null},17:{name:"miUTF16",size:null},18:{name:"miUTF32",size:null}}),T(v,"arrayClassNames",{1:"mxCELL_CLASS",2:"mxSTRUCT_CLASS",3:"mxOBJECT_CLASS",4:"mxCHAR_CLASS",5:"mxSPARSE_CLASS",6:"mxDOUBLE_CLASS",7:"mxSINGLE_CLASS",8:"mxINT8_CLASS",9:"mxUINT8_CLASS",10:"mxINT16_CLASS",11:"mxUINT16_CLASS",12:"mxINT32_CLASS",13:"mxUINT32_CLASS",14:"mxINT64_CLASS",15:"mxUINT64_CLASS"}),T(v,"headerTextBegin",1),T(v,"headerTextEnd",116),T(v,"subsysOffsetBegin",117),T(v,"subsysOffsetEnd",124),T(v,"versionOffsetBegin",125),T(v,"versionOffsetEnd",126),T(v,"endianCharsBegin",127),T(v,"endianCharsEnd",128),T(v,"firstDataTypeOffsetBegin",129),T(v,"firstDataTypeOffsetEnd",132),T(v,"numBytesOffsetBegin",133),T(v,"numBytesOffsetEnd",136);var b=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(r,e);var t,n=(t=r,function(){var e,n=m(t);if(y()){var r=m(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return p(this,e)});function r(e){return h(this,r),n.call(this,e,v)}return r}(f)}])})); //# sourceMappingURL=matfile.js.map