securityos/node_modules/riff-file/dist/riff-file.js

12 lines
5.0 KiB
JavaScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
var u="function"==typeof Object.create?Object.create:function(k){function h(){}h.prototype=k;return new h},v;if("function"==typeof Object.setPrototypeOf)v=Object.setPrototypeOf;else{var w;a:{var x={h:!0},z={};try{z.__proto__=x;w=z.h;break a}catch(k){}w=!1}v=w?function(k,h){k.__proto__=h;if(k.__proto__!==h)throw new TypeError(k+" is not extensible");return k}:null}var A=v;
function D(k,h){k.prototype=u(h.prototype);k.prototype.constructor=k;if(A)A(k,h);else for(var n in h)if("prototype"!=n)if(Object.defineProperties){var p=Object.getOwnPropertyDescriptor(h,n);p&&Object.defineProperty(k,n,p)}else k[n]=h[n]}var E=this;
function F(k){function h(){this.container="";this.chunkSize=0;this.format="";this.signature=null;this.head=0;this.uInt32={bits:32,be:!1,signed:!1,fp:!1};this.supported_containers=["RIFF","RIFX"]}function n(a,c,b){if(c){if(!a||16!==a&&32!==a&&64!==a)throw Error("Unsupported type: float, bits: "+a);c=this.a(a)}else{if(!a||1>a||53<a)throw Error("Unsupported type: int, bits: "+a);c=b?new p(a):new q(a)}this.b=c;this.offset=Math.ceil(a/8)}function p(a){a=q.call(this,a)||this;a.max=Math.pow(2,a.bits)/2-
1;a.min=-a.max-1;return a}function q(a){this.bits=a;this.c=8>a?1:Math.ceil(a/8);this.max=Math.pow(2,a)-1;this.min=0}function r(a,c){this.a=a;this.c=(1<<a-1)-1;this.b=Math.ceil((a+c)/8);this.f=Math.pow(2,-(8*this.b-1-a))}function B(a,c,b,d){d=void 0===d?a.length:d;if(d%c)throw Error("Bad buffer length.");for(b=void 0===b?0:b;b<d;b+=c){var f=a,e=c,l=b;e--;for(var g=0;g<e;g++){var m=f[l+g];f[l+g]=f[l+e];f[l+e]=m;e--}}}function y(a,c,b){b=void 0===b?a.length:b;var d=void 0===c?0:c;b=void 0===b?a.length:
b;c="";for(d=void 0===d?0:d;d<b;){var f=128,e=191,l=!1,g=a[d++];if(0<=g&&127>=g)c+=String.fromCharCode(g);else{var m=0;194<=g&&223>=g?m=1:224<=g&&239>=g?(m=2,224===a[d]&&(f=160),237===a[d]&&(e=159)):240<=g&&244>=g?(m=3,240===a[d]&&(f=144),244===a[d]&&(e=143)):l=!0;g&=(1<<8-m-1)-1;for(var t=0;t<m;t++){if(a[d]<f||a[d]>e)l=!0;g=g<<6|a[d]&63;d++}l?c+=String.fromCharCode(65533):65535>=g?c+=String.fromCharCode(g):(g-=65536,c+=String.fromCharCode((g>>10&1023)+55296,(g&1023)+56320))}}return c}function C(a,
c,b){b=void 0===b?0:b;var d=b+Math.ceil(c.bits/8);d=void 0===d?a.length:d;var f=[];b=void 0===b?0:b;var e=!0;b=void 0===b?0:b;d=void 0===d?a.length:d;e=void 0===e?!1:e;var l=c||{};var g=new n(l.bits,l.fp,l.signed);c=g.offset;var m=(d-b)%c;if(e&&(m||a.length<c))throw Error("Bad buffer length");d-=m;m=0;e=b;try{for(l.be&&B(a,c,b,d);e<d;e+=c,m++)f[m]=g.g(a,e);l.be&&B(a,c,b,d)}catch(t){throw f=t,f.message=f.constructor.name+" at index "+e+": "+a.slice(e,e+c),f;}return f[0]}r.prototype.g=function(a,c){for(var b=
(1<<this.a)-1,d="",f=this.b-1;0<=f;f--){var e=a[f+c].toString(2);d+="00000000".substring(e.length)+e}f="1"==d.charAt(0)?-1:1;d=d.substring(1);e=parseInt(d.substring(0,this.a),2);d=d.substring(this.a);if(e==b)return 0!==parseInt(d,2)?NaN:Infinity*f;0===e?(e+=1,b=parseInt(d,2)):b=parseInt("1"+d,2);return f*b*this.f*Math.pow(2,e-this.c)};q.prototype.g=function(a,c){var b=this.b(a,void 0===c?0:c);this.a(b);return b};q.prototype.b=function(a,c){c=void 0===c?0:c;for(var b=0,d=0;d<this.c;d++)b+=a[c+d]*Math.pow(256,
d);return b};q.prototype.a=function(a){if(a>this.max||a<this.min)throw new RangeError;};D(p,q);p.prototype.g=function(a,c){var b=q.prototype.b.call(this,a,void 0===c?0:c);b=this.f(b);this.a(b);return b};p.prototype.f=function(a){a>this.max&&(a-=2*this.max+2);return a};n.prototype.g=function(a,c){return this.b.g(a,void 0===c?0:c)};n.prototype.a=function(a){return 16===a?new r(5,11):32===a?new r(8,23):new r(11,52)};h.prototype.setSignature=function(a){this.head=0;this.container=this.readString(a,4);
if(-1===this.supported_containers.indexOf(this.container))throw Error("Not a supported format.");this.uInt32.be="RIFX"===this.container;this.chunkSize=this.readUInt32(a);this.format=this.readString(a,4);this.signature={chunkId:this.container,chunkSize:this.chunkSize,format:this.format,subChunks:this.a(a),chunkData:{start:0,end:this.chunkSize}}};h.prototype.findChunk=function(a,c){c=void 0===c?!1:c;for(var b=this.signature.subChunks,d=[],f=0;f<b.length;f++)if(b[f].chunkId==a)if(c)d.push(b[f]);else return b[f];
return"LIST"==a?d.length?d:null:null};h.prototype.readString=function(a,c){var b=y(a,this.head,this.head+c);this.head+=c;return b};h.prototype.readUInt32=function(a){a=C(a,this.uInt32,this.head);this.head+=4;return a};h.prototype.a=function(a){for(var c=[],b=this.head;b<=a.length-8;)c.push(this.f(a,b)),b+=8+c[c.length-1].chunkSize,b=b%2?b+1:b;return c};h.prototype.f=function(a,c){var b={chunkId:this.b(a,c),chunkSize:this.c(a,c)};"LIST"==b.chunkId?(b.format=y(a,c+8,c+12),this.head+=4,b.subChunks=this.a(a)):
(this.head=c+8+(b.chunkSize%2?b.chunkSize+1:b.chunkSize),b.chunkData={start:c+8,end:this.head});return b};h.prototype.b=function(a,c){this.head+=4;return y(a,c,c+4)};h.prototype.c=function(a,c){this.head+=4;return C(a,this.uInt32,c+4)};k.RIFFFile=h;Object.defineProperty(k,"__esModule",{value:!0})}"object"===typeof exports&&"undefined"!==typeof module?F(exports):"function"===typeof define&&define.i?define(["exports"],F):(E=E||self,F(E.riffFile={}));