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

binary-data-chunking

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-data-chunking - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

7

browser/binary-data-chunking.js

@@ -989,5 +989,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BinaryDataChunking = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

this.chunkSize = md.chunkSize;
this.payloadSize = payloadSize;
this.payloadSize = payloadSize || md.payloadSize;
this.reservedSize = RESERVED_BYTES;
this.fileSize = (md.arrayBuffer) ? md.arrayBuffer.byteLength : 0;
this.fileSize = (md.arrayBuffer) ? md.arrayBuffer.byteLength : md.fileSize;
this.totalChunks = (totalChunks) ? totalChunks : (md.totalChunks) ? md.totalChunks : 0;

@@ -1044,3 +1044,2 @@ this.checksum = checksum;

if (this._arrayBuffer) {

@@ -1165,3 +1164,2 @@ // get payload from full arrayBuffer

}
if (payload = this.scope.__getUnpackedChunk(_num)) {

@@ -1186,3 +1184,2 @@ chunk = BDC.__pack(this.scope.uid, this.currentIndex, payload);

}
if ((payload = this.scope.__getUnpackedChunk(_num)) && (typeof num !== 'number')) {

@@ -1189,0 +1186,0 @@ this.currentIndex += 1;

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

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.BinaryDataChunking=t()}}(function(){var t;return function e(t,r,n){function i(s,f){if(!r[s]){if(!t[s]){var h="function"==typeof require&&require;if(!f&&h)return h(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var a=r[s]={exports:{}};t[s][0].call(a.exports,function(e){var r=t[s][1][e];return i(r?r:e)},a,a.exports,e,t,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,e,r){function n(t){"object"!=typeof t&&(t={}),this._identifier=t.identifier||"id",this._store=[],this._idx=[],t.emitEvents?(this._emitEvents=!0,this.events=new i):this._emitEvents=!1}var i=t("tiny-emitter");n.prototype.emitEvent=function(t,e,r){this._emitEvents&&!r&&this.events.emit(t,e)},n.prototype.getIdentifiers=function(){for(var t=[],e=this._store.length-1;e>=0;e-=1)t[t.length]=this._store[e][this._identifier];return t},n.prototype.getRecord=function(t){for(var e=this._store.length-1;e>=0;e-=1)if(this._store[e][this._identifier]===t)return this._store[e]},n.prototype.exists=function(t){return this.getIndex(t)>=0},n.prototype.getIndex=function(t){for(var e=this._idx.length-1;e>=0;e-=1)if(this._idx[e]===t)return e;return-1},n.prototype.addRecord=function(t){if("object"!=typeof t)throw new Error("cannot add non-object records.");if(!t[this._identifier])throw new Error("cannot add a record with no `"+this._identifier+"` property specified.");var e=this.removeRecord(t[this._identifier],!0);return this._idx[this._idx.length]=t[this._identifier],this._store[this._store.length]=t,setTimeout(function(){e?setTimeout(this.emitEvent.bind(this,"update",t),0):setTimeout(this.emitEvent.bind(this,"add",t),0)}.bind(this),0),!0},n.prototype.removeRecord=function(t,e){var r=this.getIndex(t);if(0>r)return!1;for(var n=r;n>=0;n-=1)if(this._store[n]&&this._store[n][this._identifier]===t)return this._store.splice(n,1),this._idx.splice(r,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;for(var i=this._store.length-1;i>=r;i-=1)if(this._store[n]&&this._store[i][this._identifier]===t)return this._store.splice(i,1),this._idx.splice(r,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;return!1},n.prototype.forEachRecord=function(t){var e=0,r=this,n=function(){};return setTimeout(function(){for(var i=r._store.length-1;i>=0;i-=1)e+=1,setTimeout(t(r._store[i]),0);setTimeout(n(e),0)},0),{"finally":function(t){n=t}}},n.prototype.getCount=function(){return this._store.length},n.prototype.removeAll=function(){for(var t=this._store.length-1;t>=0;t-=1)delete this._store[t];this._store=[]},e.exports=n},{"tiny-emitter":3}],2:[function(e,r,n){!function(e){if("object"==typeof n)r.exports=e();else if("function"==typeof t&&t.amd)t(e);else{var i;try{i=window}catch(o){i=self}i.SparkMD5=e()}}(function(t){"use strict";function e(t,e,r,n,i,o){return e=m(m(e,t),m(n,o)),m(e<<i|e>>>32-i,r)}function r(t,r,n,i,o,s,f){return e(r&n|~r&i,t,r,o,s,f)}function n(t,r,n,i,o,s,f){return e(r&i|n&~i,t,r,o,s,f)}function i(t,r,n,i,o,s,f){return e(r^n^i,t,r,o,s,f)}function o(t,r,n,i,o,s,f){return e(n^(r|~i),t,r,o,s,f)}function s(t,e){var s=t[0],f=t[1],h=t[2],u=t[3];s=r(s,f,h,u,e[0],7,-680876936),u=r(u,s,f,h,e[1],12,-389564586),h=r(h,u,s,f,e[2],17,606105819),f=r(f,h,u,s,e[3],22,-1044525330),s=r(s,f,h,u,e[4],7,-176418897),u=r(u,s,f,h,e[5],12,1200080426),h=r(h,u,s,f,e[6],17,-1473231341),f=r(f,h,u,s,e[7],22,-45705983),s=r(s,f,h,u,e[8],7,1770035416),u=r(u,s,f,h,e[9],12,-1958414417),h=r(h,u,s,f,e[10],17,-42063),f=r(f,h,u,s,e[11],22,-1990404162),s=r(s,f,h,u,e[12],7,1804603682),u=r(u,s,f,h,e[13],12,-40341101),h=r(h,u,s,f,e[14],17,-1502002290),f=r(f,h,u,s,e[15],22,1236535329),s=n(s,f,h,u,e[1],5,-165796510),u=n(u,s,f,h,e[6],9,-1069501632),h=n(h,u,s,f,e[11],14,643717713),f=n(f,h,u,s,e[0],20,-373897302),s=n(s,f,h,u,e[5],5,-701558691),u=n(u,s,f,h,e[10],9,38016083),h=n(h,u,s,f,e[15],14,-660478335),f=n(f,h,u,s,e[4],20,-405537848),s=n(s,f,h,u,e[9],5,568446438),u=n(u,s,f,h,e[14],9,-1019803690),h=n(h,u,s,f,e[3],14,-187363961),f=n(f,h,u,s,e[8],20,1163531501),s=n(s,f,h,u,e[13],5,-1444681467),u=n(u,s,f,h,e[2],9,-51403784),h=n(h,u,s,f,e[7],14,1735328473),f=n(f,h,u,s,e[12],20,-1926607734),s=i(s,f,h,u,e[5],4,-378558),u=i(u,s,f,h,e[8],11,-2022574463),h=i(h,u,s,f,e[11],16,1839030562),f=i(f,h,u,s,e[14],23,-35309556),s=i(s,f,h,u,e[1],4,-1530992060),u=i(u,s,f,h,e[4],11,1272893353),h=i(h,u,s,f,e[7],16,-155497632),f=i(f,h,u,s,e[10],23,-1094730640),s=i(s,f,h,u,e[13],4,681279174),u=i(u,s,f,h,e[0],11,-358537222),h=i(h,u,s,f,e[3],16,-722521979),f=i(f,h,u,s,e[6],23,76029189),s=i(s,f,h,u,e[9],4,-640364487),u=i(u,s,f,h,e[12],11,-421815835),h=i(h,u,s,f,e[15],16,530742520),f=i(f,h,u,s,e[2],23,-995338651),s=o(s,f,h,u,e[0],6,-198630844),u=o(u,s,f,h,e[7],10,1126891415),h=o(h,u,s,f,e[14],15,-1416354905),f=o(f,h,u,s,e[5],21,-57434055),s=o(s,f,h,u,e[12],6,1700485571),u=o(u,s,f,h,e[3],10,-1894986606),h=o(h,u,s,f,e[10],15,-1051523),f=o(f,h,u,s,e[1],21,-2054922799),s=o(s,f,h,u,e[8],6,1873313359),u=o(u,s,f,h,e[15],10,-30611744),h=o(h,u,s,f,e[6],15,-1560198380),f=o(f,h,u,s,e[13],21,1309151649),s=o(s,f,h,u,e[4],6,-145523070),u=o(u,s,f,h,e[11],10,-1120210379),h=o(h,u,s,f,e[2],15,718787259),f=o(f,h,u,s,e[9],21,-343485551),t[0]=m(s,t[0]),t[1]=m(f,t[1]),t[2]=m(h,t[2]),t[3]=m(u,t[3])}function f(t){var e,r=[];for(e=0;64>e;e+=4)r[e>>2]=t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24);return r}function h(t){var e,r=[];for(e=0;64>e;e+=4)r[e>>2]=t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24);return r}function u(t){var e,r,n,i,o,h,u=t.length,a=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)s(a,f(t.substring(e-64,e)));for(t=t.substring(e-64),r=t.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;r>e;e+=1)n[e>>2]|=t.charCodeAt(e)<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(s(a,n),e=0;16>e;e+=1)n[e]=0;return i=8*u,i=i.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(i[2],16),h=parseInt(i[1],16)||0,n[14]=o,n[15]=h,s(a,n),a}function a(t){var e,r,n,i,o,f,u=t.length,a=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)s(a,h(t.subarray(e-64,e)));for(t=u>e-64?t.subarray(e-64):new Uint8Array(0),r=t.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;r>e;e+=1)n[e>>2]|=t[e]<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(s(a,n),e=0;16>e;e+=1)n[e]=0;return i=8*u,i=i.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(i[2],16),f=parseInt(i[1],16)||0,n[14]=o,n[15]=f,s(a,n),a}function c(t){var e,r="";for(e=0;4>e;e+=1)r+=b[t>>8*e+4&15]+b[t>>8*e&15];return r}function p(t){var e;for(e=0;e<t.length;e+=1)t[e]=c(t[e]);return t.join("")}function y(t){return/[\u0080-\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function d(t,e){var r,n=t.length,i=new ArrayBuffer(n),o=new Uint8Array(i);for(r=0;n>r;r+=1)o[r]=t.charCodeAt(r);return e?o:i}function l(t){return String.fromCharCode.apply(null,new Uint8Array(t))}function _(t,e,r){var n=new Uint8Array(t.byteLength+e.byteLength);return n.set(new Uint8Array(t)),n.set(new Uint8Array(e),t.byteLength),r?n:n.buffer}function g(t){var e,r=[],n=t.length;for(e=0;n-1>e;e+=2)r.push(parseInt(t.substr(e,2),16));return String.fromCharCode.apply(String,r)}function v(){this.reset()}var m=function(t,e){return t+e&4294967295},b=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return"5d41402abc4b2a76b9719d911017c592"!==p(u("hello"))&&(m=function(t,e){var r=(65535&t)+(65535&e),n=(t>>16)+(e>>16)+(r>>16);return n<<16|65535&r}),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||!function(){function e(t,e){return t=0|t||0,0>t?Math.max(t+e,0):Math.min(t,e)}ArrayBuffer.prototype.slice=function(r,n){var i,o,s,f,h=this.byteLength,u=e(r,h),a=h;return n!==t&&(a=e(n,h)),u>a?new ArrayBuffer(0):(i=a-u,o=new ArrayBuffer(i),s=new Uint8Array(o),f=new Uint8Array(this,u,i),s.set(f),o)}}(),v.prototype.append=function(t){return this.appendBinary(y(t)),this},v.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var e,r=this._buff.length;for(e=64;r>=e;e+=64)s(this._hash,f(this._buff.substring(e-64,e)));return this._buff=this._buff.substring(e-64),this},v.prototype.end=function(t){var e,r,n=this._buff,i=n.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;i>e;e+=1)o[e>>2]|=n.charCodeAt(e)<<(e%4<<3);return this._finish(o,i),r=p(this._hash),t&&(r=g(r)),this.reset(),r},v.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},v.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},v.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},v.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},v.prototype._finish=function(t,e){var r,n,i,o=e;if(t[o>>2]|=128<<(o%4<<3),o>55)for(s(this._hash,t),o=0;16>o;o+=1)t[o]=0;r=8*this._length,r=r.toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(r[2],16),i=parseInt(r[1],16)||0,t[14]=n,t[15]=i,s(this._hash,t)},v.hash=function(t,e){return v.hashBinary(y(t),e)},v.hashBinary=function(t,e){var r=u(t),n=p(r);return e?g(n):n},v.ArrayBuffer=function(){this.reset()},v.ArrayBuffer.prototype.append=function(t){var e,r=_(this._buff.buffer,t,!0),n=r.length;for(this._length+=t.byteLength,e=64;n>=e;e+=64)s(this._hash,h(r.subarray(e-64,e)));return this._buff=n>e-64?new Uint8Array(r.buffer.slice(e-64)):new Uint8Array(0),this},v.ArrayBuffer.prototype.end=function(t){var e,r,n=this._buff,i=n.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;i>e;e+=1)o[e>>2]|=n[e]<<(e%4<<3);return this._finish(o,i),r=p(this._hash),t&&(r=g(r)),this.reset(),r},v.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},v.ArrayBuffer.prototype.getState=function(){var t=v.prototype.getState.call(this);return t.buff=l(t.buff),t},v.ArrayBuffer.prototype.setState=function(t){return t.buff=d(t.buff,!0),v.prototype.setState.call(this,t)},v.ArrayBuffer.prototype.destroy=v.prototype.destroy,v.ArrayBuffer.prototype._finish=v.prototype._finish,v.ArrayBuffer.hash=function(t,e){var r=a(new Uint8Array(t)),n=p(r);return e?g(n):n},v})},{}],3:[function(t,e,r){function n(){}n.prototype={on:function(t,e,r){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:e,ctx:r}),this},once:function(t,e,r){function n(){i.off(t,n),e.apply(r,arguments)}var i=this;return n._=e,this.on(t,n,r)},emit:function(t){var e=[].slice.call(arguments,1),r=((this.e||(this.e={}))[t]||[]).slice(),n=0,i=r.length;for(n;i>n;n++)r[n].fn.apply(r[n].ctx,e);return this},off:function(t,e){var r=this.e||(this.e={}),n=r[t],i=[];if(n&&e)for(var o=0,s=n.length;s>o;o++)n[o].fn!==e&&n[o].fn._!==e&&i.push(n[o]);return i.length?r[t]=i:delete r[t],this}},e.exports=n},{}],4:[function(t,e,r){function n(){return Math.floor(65535*Math.random()+1)}function i(t,e){var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer}function o(t){var e,r,i,o;if("object"!=typeof t)throw new Error("metadata object must be passed in");if(!t.name)throw new Error("no name specified");if(!t.mimeType)throw new Error("no mimeType specified");if(!t.chunkSize)throw new Error("no chunkSize specified");if(t.arrayBuffer&&("function"!=typeof t.arrayBuffer.toString||"[object ArrayBuffer]"!==t.arrayBuffer.toString()))throw new Error("arrayBuffer must be an actual ArrayBuffer object");if(!t.arrayBuffer&&!t.uid)throw new Error("arrayBuffer or uid must be specified");if(t.arrayBuffer&&t.uid)throw new Error("cannot manually assign uid");t.uid||(t.uid=n()),t.arrayBuffer?(r=t.chunkSize-u,e=Math.ceil(t.arrayBuffer.byteLength/r),i=h.ArrayBuffer.hash(t.arrayBuffer),o=!0):i=t.checksum,this.uid=t.uid,this.name=t.name,this.existsLocally=o||!1,this.mimeType=t.mimeType,this.chunkSize=t.chunkSize,this.payloadSize=r,this.reservedSize=u,this.fileSize=t.arrayBuffer?t.arrayBuffer.byteLength:0,this.totalChunks=e?e:t.totalChunks?t.totalChunks:0,this.checksum=i,this.generatedChecksum,this.currentIndex=0,this.chunksReceived=0,this._arrayBuffer=t.arrayBuffer?t.arrayBuffer:null,this._chunks=[],p.addRecord(this)}function s(t){this.scope=t,this.currentIndex=0}var f=t("array-keys"),h=t("spark-md5"),u=8,a=0,c=4,p=new f({identifier:"uid"});o.prototype.getMetadata=function(){return{uid:this.uid,name:this.name,mimeType:this.mimeType,chunkSize:this.chunkSize,payloadSize:this.payloadSize,reservedSize:this.reservedSize,fileSize:this.fileSize,totalChunks:this.totalChunks,checksum:this.checksum}},o.prototype.getFile=function(t){this._arrayBuffer=this._chunks[0];for(var e=1;e<this._chunks.length;e+=1)this._arrayBuffer=i(this._arrayBuffer,this._chunks[e]);this.generatedChecksum=h.ArrayBuffer.hash(this._arrayBuffer),t(this._arrayBuffer,this.generatedChecksum)},o.prototype.onChunkReceived=function(){},o.prototype.onCompleted=function(){},o.prototype.getTransferObject=function(){return new s(this)},o.prototype.__getUnpackedChunk=function(t){var e;if(this._arrayBuffer){var r=this.payloadSize*(t+1)-this.payloadSize;if(r>=this.fileSize)return;var n=r+this.payloadSize;n=n>this.fileSize?this.fileSize:n,e=this._arrayBuffer.slice(r,n)}else this._chunks[t]&&(e=this._chunks[t]);return e},o.prototype.clearData=function(){p.removeRecord(this.uid),delete this._arrayBuffer,delete this},o.__pack=function(t,e,r){var n=new ArrayBuffer(r.byteLength+u),i=new DataView(n);return i.setInt32(a,t),i.setInt32(c,e),new Uint8Array(n,0,n.byteLength).set(new Uint8Array(r),u),n},o.unpack=function(t){var e=new DataView(t),r=e.getInt32(a),n=e.getInt32(c),i=new Uint8Array(t.slice(u));return[r,n,i]},o.submitChunk=function(t){var e=this.unpack(t),r=e[0],n=e[1],i=e[2],o=p.getRecord(r);return o?(o._chunks[n]=i,o.chunksReceived+=1,o.onChunkReceived(i,n),o.chunksReceived===o.totalChunks&&(o.existsLocally=!0,o.onCompleted()),p.addRecord(o),!0):!1},o.getFileObject=function(t){return p.getRecord(parseInt(t))},s.prototype.forEachChunk=function(t,e){for(var r,n=0;this.currentIndex<this.scope.totalChunks;)n=this.currentIndex,(r=this.getChunk())&&t(r,n);e()},s.prototype.forEachReceivedChunk=function(t,e){var r,n=0,i=setInterval(function(){return n=this.currentIndex,(r=this.getUnpackedChunk())?t(chunk,n):this.currentIndex===self.totalChunks-1?(clearInterval(i),e()):void 0}.bind(this),100)},s.prototype.getChunk=function(t){var e,r,n=this.currentIndex;if("number"==typeof t){if(0>t)return;n=t}return(e=this.scope.__getUnpackedChunk(n))&&(r=o.__pack(this.scope.uid,this.currentIndex,e),r&&"number"!=typeof t&&(this.currentIndex+=1)),r},s.prototype.getUnpackedChunk=function(t){var e,r=this.currentIndex;if("number"==typeof t){if(0>t)return;r=t}return(e=this.scope.__getUnpackedChunk(r))&&"number"!=typeof t&&(this.currentIndex+=1),e},e.exports=o},{"array-keys":1,"spark-md5":2}]},{},[4])(4)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.BinaryDataChunking=t()}}(function(){var t;return function e(t,r,n){function i(s,f){if(!r[s]){if(!t[s]){var h="function"==typeof require&&require;if(!f&&h)return h(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var a=r[s]={exports:{}};t[s][0].call(a.exports,function(e){var r=t[s][1][e];return i(r?r:e)},a,a.exports,e,t,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,e,r){function n(t){"object"!=typeof t&&(t={}),this._identifier=t.identifier||"id",this._store=[],this._idx=[],t.emitEvents?(this._emitEvents=!0,this.events=new i):this._emitEvents=!1}var i=t("tiny-emitter");n.prototype.emitEvent=function(t,e,r){this._emitEvents&&!r&&this.events.emit(t,e)},n.prototype.getIdentifiers=function(){for(var t=[],e=this._store.length-1;e>=0;e-=1)t[t.length]=this._store[e][this._identifier];return t},n.prototype.getRecord=function(t){for(var e=this._store.length-1;e>=0;e-=1)if(this._store[e][this._identifier]===t)return this._store[e]},n.prototype.exists=function(t){return this.getIndex(t)>=0},n.prototype.getIndex=function(t){for(var e=this._idx.length-1;e>=0;e-=1)if(this._idx[e]===t)return e;return-1},n.prototype.addRecord=function(t){if("object"!=typeof t)throw new Error("cannot add non-object records.");if(!t[this._identifier])throw new Error("cannot add a record with no `"+this._identifier+"` property specified.");var e=this.removeRecord(t[this._identifier],!0);return this._idx[this._idx.length]=t[this._identifier],this._store[this._store.length]=t,setTimeout(function(){e?setTimeout(this.emitEvent.bind(this,"update",t),0):setTimeout(this.emitEvent.bind(this,"add",t),0)}.bind(this),0),!0},n.prototype.removeRecord=function(t,e){var r=this.getIndex(t);if(0>r)return!1;for(var n=r;n>=0;n-=1)if(this._store[n]&&this._store[n][this._identifier]===t)return this._store.splice(n,1),this._idx.splice(r,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;for(var i=this._store.length-1;i>=r;i-=1)if(this._store[n]&&this._store[i][this._identifier]===t)return this._store.splice(i,1),this._idx.splice(r,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;return!1},n.prototype.forEachRecord=function(t){var e=0,r=this,n=function(){};return setTimeout(function(){for(var i=r._store.length-1;i>=0;i-=1)e+=1,setTimeout(t(r._store[i]),0);setTimeout(n(e),0)},0),{"finally":function(t){n=t}}},n.prototype.getCount=function(){return this._store.length},n.prototype.removeAll=function(){for(var t=this._store.length-1;t>=0;t-=1)delete this._store[t];this._store=[]},e.exports=n},{"tiny-emitter":3}],2:[function(e,r,n){!function(e){if("object"==typeof n)r.exports=e();else if("function"==typeof t&&t.amd)t(e);else{var i;try{i=window}catch(o){i=self}i.SparkMD5=e()}}(function(t){"use strict";function e(t,e,r,n,i,o){return e=m(m(e,t),m(n,o)),m(e<<i|e>>>32-i,r)}function r(t,r,n,i,o,s,f){return e(r&n|~r&i,t,r,o,s,f)}function n(t,r,n,i,o,s,f){return e(r&i|n&~i,t,r,o,s,f)}function i(t,r,n,i,o,s,f){return e(r^n^i,t,r,o,s,f)}function o(t,r,n,i,o,s,f){return e(n^(r|~i),t,r,o,s,f)}function s(t,e){var s=t[0],f=t[1],h=t[2],u=t[3];s=r(s,f,h,u,e[0],7,-680876936),u=r(u,s,f,h,e[1],12,-389564586),h=r(h,u,s,f,e[2],17,606105819),f=r(f,h,u,s,e[3],22,-1044525330),s=r(s,f,h,u,e[4],7,-176418897),u=r(u,s,f,h,e[5],12,1200080426),h=r(h,u,s,f,e[6],17,-1473231341),f=r(f,h,u,s,e[7],22,-45705983),s=r(s,f,h,u,e[8],7,1770035416),u=r(u,s,f,h,e[9],12,-1958414417),h=r(h,u,s,f,e[10],17,-42063),f=r(f,h,u,s,e[11],22,-1990404162),s=r(s,f,h,u,e[12],7,1804603682),u=r(u,s,f,h,e[13],12,-40341101),h=r(h,u,s,f,e[14],17,-1502002290),f=r(f,h,u,s,e[15],22,1236535329),s=n(s,f,h,u,e[1],5,-165796510),u=n(u,s,f,h,e[6],9,-1069501632),h=n(h,u,s,f,e[11],14,643717713),f=n(f,h,u,s,e[0],20,-373897302),s=n(s,f,h,u,e[5],5,-701558691),u=n(u,s,f,h,e[10],9,38016083),h=n(h,u,s,f,e[15],14,-660478335),f=n(f,h,u,s,e[4],20,-405537848),s=n(s,f,h,u,e[9],5,568446438),u=n(u,s,f,h,e[14],9,-1019803690),h=n(h,u,s,f,e[3],14,-187363961),f=n(f,h,u,s,e[8],20,1163531501),s=n(s,f,h,u,e[13],5,-1444681467),u=n(u,s,f,h,e[2],9,-51403784),h=n(h,u,s,f,e[7],14,1735328473),f=n(f,h,u,s,e[12],20,-1926607734),s=i(s,f,h,u,e[5],4,-378558),u=i(u,s,f,h,e[8],11,-2022574463),h=i(h,u,s,f,e[11],16,1839030562),f=i(f,h,u,s,e[14],23,-35309556),s=i(s,f,h,u,e[1],4,-1530992060),u=i(u,s,f,h,e[4],11,1272893353),h=i(h,u,s,f,e[7],16,-155497632),f=i(f,h,u,s,e[10],23,-1094730640),s=i(s,f,h,u,e[13],4,681279174),u=i(u,s,f,h,e[0],11,-358537222),h=i(h,u,s,f,e[3],16,-722521979),f=i(f,h,u,s,e[6],23,76029189),s=i(s,f,h,u,e[9],4,-640364487),u=i(u,s,f,h,e[12],11,-421815835),h=i(h,u,s,f,e[15],16,530742520),f=i(f,h,u,s,e[2],23,-995338651),s=o(s,f,h,u,e[0],6,-198630844),u=o(u,s,f,h,e[7],10,1126891415),h=o(h,u,s,f,e[14],15,-1416354905),f=o(f,h,u,s,e[5],21,-57434055),s=o(s,f,h,u,e[12],6,1700485571),u=o(u,s,f,h,e[3],10,-1894986606),h=o(h,u,s,f,e[10],15,-1051523),f=o(f,h,u,s,e[1],21,-2054922799),s=o(s,f,h,u,e[8],6,1873313359),u=o(u,s,f,h,e[15],10,-30611744),h=o(h,u,s,f,e[6],15,-1560198380),f=o(f,h,u,s,e[13],21,1309151649),s=o(s,f,h,u,e[4],6,-145523070),u=o(u,s,f,h,e[11],10,-1120210379),h=o(h,u,s,f,e[2],15,718787259),f=o(f,h,u,s,e[9],21,-343485551),t[0]=m(s,t[0]),t[1]=m(f,t[1]),t[2]=m(h,t[2]),t[3]=m(u,t[3])}function f(t){var e,r=[];for(e=0;64>e;e+=4)r[e>>2]=t.charCodeAt(e)+(t.charCodeAt(e+1)<<8)+(t.charCodeAt(e+2)<<16)+(t.charCodeAt(e+3)<<24);return r}function h(t){var e,r=[];for(e=0;64>e;e+=4)r[e>>2]=t[e]+(t[e+1]<<8)+(t[e+2]<<16)+(t[e+3]<<24);return r}function u(t){var e,r,n,i,o,h,u=t.length,a=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)s(a,f(t.substring(e-64,e)));for(t=t.substring(e-64),r=t.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;r>e;e+=1)n[e>>2]|=t.charCodeAt(e)<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(s(a,n),e=0;16>e;e+=1)n[e]=0;return i=8*u,i=i.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(i[2],16),h=parseInt(i[1],16)||0,n[14]=o,n[15]=h,s(a,n),a}function a(t){var e,r,n,i,o,f,u=t.length,a=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)s(a,h(t.subarray(e-64,e)));for(t=u>e-64?t.subarray(e-64):new Uint8Array(0),r=t.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;r>e;e+=1)n[e>>2]|=t[e]<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(s(a,n),e=0;16>e;e+=1)n[e]=0;return i=8*u,i=i.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(i[2],16),f=parseInt(i[1],16)||0,n[14]=o,n[15]=f,s(a,n),a}function c(t){var e,r="";for(e=0;4>e;e+=1)r+=b[t>>8*e+4&15]+b[t>>8*e&15];return r}function p(t){var e;for(e=0;e<t.length;e+=1)t[e]=c(t[e]);return t.join("")}function y(t){return/[\u0080-\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function d(t,e){var r,n=t.length,i=new ArrayBuffer(n),o=new Uint8Array(i);for(r=0;n>r;r+=1)o[r]=t.charCodeAt(r);return e?o:i}function l(t){return String.fromCharCode.apply(null,new Uint8Array(t))}function _(t,e,r){var n=new Uint8Array(t.byteLength+e.byteLength);return n.set(new Uint8Array(t)),n.set(new Uint8Array(e),t.byteLength),r?n:n.buffer}function g(t){var e,r=[],n=t.length;for(e=0;n-1>e;e+=2)r.push(parseInt(t.substr(e,2),16));return String.fromCharCode.apply(String,r)}function v(){this.reset()}var m=function(t,e){return t+e&4294967295},b=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return"5d41402abc4b2a76b9719d911017c592"!==p(u("hello"))&&(m=function(t,e){var r=(65535&t)+(65535&e),n=(t>>16)+(e>>16)+(r>>16);return n<<16|65535&r}),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||!function(){function e(t,e){return t=0|t||0,0>t?Math.max(t+e,0):Math.min(t,e)}ArrayBuffer.prototype.slice=function(r,n){var i,o,s,f,h=this.byteLength,u=e(r,h),a=h;return n!==t&&(a=e(n,h)),u>a?new ArrayBuffer(0):(i=a-u,o=new ArrayBuffer(i),s=new Uint8Array(o),f=new Uint8Array(this,u,i),s.set(f),o)}}(),v.prototype.append=function(t){return this.appendBinary(y(t)),this},v.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var e,r=this._buff.length;for(e=64;r>=e;e+=64)s(this._hash,f(this._buff.substring(e-64,e)));return this._buff=this._buff.substring(e-64),this},v.prototype.end=function(t){var e,r,n=this._buff,i=n.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;i>e;e+=1)o[e>>2]|=n.charCodeAt(e)<<(e%4<<3);return this._finish(o,i),r=p(this._hash),t&&(r=g(r)),this.reset(),r},v.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},v.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},v.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},v.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},v.prototype._finish=function(t,e){var r,n,i,o=e;if(t[o>>2]|=128<<(o%4<<3),o>55)for(s(this._hash,t),o=0;16>o;o+=1)t[o]=0;r=8*this._length,r=r.toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(r[2],16),i=parseInt(r[1],16)||0,t[14]=n,t[15]=i,s(this._hash,t)},v.hash=function(t,e){return v.hashBinary(y(t),e)},v.hashBinary=function(t,e){var r=u(t),n=p(r);return e?g(n):n},v.ArrayBuffer=function(){this.reset()},v.ArrayBuffer.prototype.append=function(t){var e,r=_(this._buff.buffer,t,!0),n=r.length;for(this._length+=t.byteLength,e=64;n>=e;e+=64)s(this._hash,h(r.subarray(e-64,e)));return this._buff=n>e-64?new Uint8Array(r.buffer.slice(e-64)):new Uint8Array(0),this},v.ArrayBuffer.prototype.end=function(t){var e,r,n=this._buff,i=n.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(e=0;i>e;e+=1)o[e>>2]|=n[e]<<(e%4<<3);return this._finish(o,i),r=p(this._hash),t&&(r=g(r)),this.reset(),r},v.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},v.ArrayBuffer.prototype.getState=function(){var t=v.prototype.getState.call(this);return t.buff=l(t.buff),t},v.ArrayBuffer.prototype.setState=function(t){return t.buff=d(t.buff,!0),v.prototype.setState.call(this,t)},v.ArrayBuffer.prototype.destroy=v.prototype.destroy,v.ArrayBuffer.prototype._finish=v.prototype._finish,v.ArrayBuffer.hash=function(t,e){var r=a(new Uint8Array(t)),n=p(r);return e?g(n):n},v})},{}],3:[function(t,e,r){function n(){}n.prototype={on:function(t,e,r){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:e,ctx:r}),this},once:function(t,e,r){function n(){i.off(t,n),e.apply(r,arguments)}var i=this;return n._=e,this.on(t,n,r)},emit:function(t){var e=[].slice.call(arguments,1),r=((this.e||(this.e={}))[t]||[]).slice(),n=0,i=r.length;for(n;i>n;n++)r[n].fn.apply(r[n].ctx,e);return this},off:function(t,e){var r=this.e||(this.e={}),n=r[t],i=[];if(n&&e)for(var o=0,s=n.length;s>o;o++)n[o].fn!==e&&n[o].fn._!==e&&i.push(n[o]);return i.length?r[t]=i:delete r[t],this}},e.exports=n},{}],4:[function(t,e,r){function n(){return Math.floor(65535*Math.random()+1)}function i(t,e){var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer}function o(t){var e,r,i,o;if("object"!=typeof t)throw new Error("metadata object must be passed in");if(!t.name)throw new Error("no name specified");if(!t.mimeType)throw new Error("no mimeType specified");if(!t.chunkSize)throw new Error("no chunkSize specified");if(t.arrayBuffer&&("function"!=typeof t.arrayBuffer.toString||"[object ArrayBuffer]"!==t.arrayBuffer.toString()))throw new Error("arrayBuffer must be an actual ArrayBuffer object");if(!t.arrayBuffer&&!t.uid)throw new Error("arrayBuffer or uid must be specified");if(t.arrayBuffer&&t.uid)throw new Error("cannot manually assign uid");t.uid||(t.uid=n()),t.arrayBuffer?(r=t.chunkSize-u,e=Math.ceil(t.arrayBuffer.byteLength/r),i=h.ArrayBuffer.hash(t.arrayBuffer),o=!0):i=t.checksum,this.uid=t.uid,this.name=t.name,this.existsLocally=o||!1,this.mimeType=t.mimeType,this.chunkSize=t.chunkSize,this.payloadSize=r||t.payloadSize,this.reservedSize=u,this.fileSize=t.arrayBuffer?t.arrayBuffer.byteLength:t.fileSize,this.totalChunks=e?e:t.totalChunks?t.totalChunks:0,this.checksum=i,this.generatedChecksum,this.currentIndex=0,this.chunksReceived=0,this._arrayBuffer=t.arrayBuffer?t.arrayBuffer:null,this._chunks=[],p.addRecord(this)}function s(t){this.scope=t,this.currentIndex=0}var f=t("array-keys"),h=t("spark-md5"),u=8,a=0,c=4,p=new f({identifier:"uid"});o.prototype.getMetadata=function(){return{uid:this.uid,name:this.name,mimeType:this.mimeType,chunkSize:this.chunkSize,payloadSize:this.payloadSize,reservedSize:this.reservedSize,fileSize:this.fileSize,totalChunks:this.totalChunks,checksum:this.checksum}},o.prototype.getFile=function(t){this._arrayBuffer=this._chunks[0];for(var e=1;e<this._chunks.length;e+=1)this._arrayBuffer=i(this._arrayBuffer,this._chunks[e]);this.generatedChecksum=h.ArrayBuffer.hash(this._arrayBuffer),t(this._arrayBuffer,this.generatedChecksum)},o.prototype.onChunkReceived=function(){},o.prototype.onCompleted=function(){},o.prototype.getTransferObject=function(){return new s(this)},o.prototype.__getUnpackedChunk=function(t){var e;if(this._arrayBuffer){var r=this.payloadSize*(t+1)-this.payloadSize;if(r>=this.fileSize)return;var n=r+this.payloadSize;n=n>this.fileSize?this.fileSize:n,e=this._arrayBuffer.slice(r,n)}else this._chunks[t]&&(e=this._chunks[t]);return e},o.prototype.clearData=function(){p.removeRecord(this.uid),delete this._arrayBuffer,delete this},o.__pack=function(t,e,r){var n=new ArrayBuffer(r.byteLength+u),i=new DataView(n);return i.setInt32(a,t),i.setInt32(c,e),new Uint8Array(n,0,n.byteLength).set(new Uint8Array(r),u),n},o.unpack=function(t){var e=new DataView(t),r=e.getInt32(a),n=e.getInt32(c),i=new Uint8Array(t.slice(u));return[r,n,i]},o.submitChunk=function(t){var e=this.unpack(t),r=e[0],n=e[1],i=e[2],o=p.getRecord(r);return o?(o._chunks[n]=i,o.chunksReceived+=1,o.onChunkReceived(i,n),o.chunksReceived===o.totalChunks&&(o.existsLocally=!0,o.onCompleted()),p.addRecord(o),!0):!1},o.getFileObject=function(t){return p.getRecord(parseInt(t))},s.prototype.forEachChunk=function(t,e){for(var r,n=0;this.currentIndex<this.scope.totalChunks;)n=this.currentIndex,(r=this.getChunk())&&t(r,n);e()},s.prototype.forEachReceivedChunk=function(t,e){var r,n=0,i=setInterval(function(){return n=this.currentIndex,(r=this.getUnpackedChunk())?t(chunk,n):this.currentIndex===self.totalChunks-1?(clearInterval(i),e()):void 0}.bind(this),100)},s.prototype.getChunk=function(t){var e,r,n=this.currentIndex;if("number"==typeof t){if(0>t)return;n=t}return(e=this.scope.__getUnpackedChunk(n))&&(r=o.__pack(this.scope.uid,this.currentIndex,e),r&&"number"!=typeof t&&(this.currentIndex+=1)),r},s.prototype.getUnpackedChunk=function(t){var e,r=this.currentIndex;if("number"==typeof t){if(0>t)return;r=t}return(e=this.scope.__getUnpackedChunk(r))&&"number"!=typeof t&&(this.currentIndex+=1),e},e.exports=o},{"array-keys":1,"spark-md5":2}]},{},[4])(4)});
{
"name": "binary-data-chunking",
"version": "3.0.0",
"version": "3.0.1",
"description": "A small library that simplifies sending large amounts of chunked binary data",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -58,5 +58,5 @@ var ArrayKeys = require('array-keys');

this.chunkSize = md.chunkSize;
this.payloadSize = payloadSize;
this.payloadSize = payloadSize || md.payloadSize;
this.reservedSize = RESERVED_BYTES;
this.fileSize = (md.arrayBuffer) ? md.arrayBuffer.byteLength : 0;
this.fileSize = (md.arrayBuffer) ? md.arrayBuffer.byteLength : md.fileSize;
this.totalChunks = (totalChunks) ? totalChunks : (md.totalChunks) ? md.totalChunks : 0;

@@ -113,3 +113,2 @@ this.checksum = checksum;

if (this._arrayBuffer) {

@@ -234,3 +233,2 @@ // get payload from full arrayBuffer

}
if (payload = this.scope.__getUnpackedChunk(_num)) {

@@ -255,3 +253,2 @@ chunk = BDC.__pack(this.scope.uid, this.currentIndex, payload);

}
if ((payload = this.scope.__getUnpackedChunk(_num)) && (typeof num !== 'number')) {

@@ -258,0 +255,0 @@ this.currentIndex += 1;

@@ -42,3 +42,6 @@ if (typeof define !== 'function') {

env.receiver = new env.BDC(env.sender.getMetadata());
test.assert(env.receiver.totalChunks, env.totalChunks);
test.assertAnd(env.receiver.fileSize, env.sender.fileSize, 'fileSize');
test.assertAnd(env.receiver.chunkSize, 16000, 'chunkSize');
test.assertAnd(env.receiver.payloadSize, env.sender.payloadSize, 'payloadSize');
test.assert(env.receiver.totalChunks, env.totalChunks, 'totalChunks');
}

@@ -58,9 +61,9 @@ },

var chunk = env.sto.getChunk();
test.assertAnd(chunk.byteLength, 16000)
test.assertAnd(chunk.byteLength, 16000, 'byteLength ' + chunk.byteLength + ' != ' + 16000)
env.BDC.submitChunk(chunk);
test.assertAnd(env.sto.currentIndex, 1);
test.assertAnd(env.sender.chunkSize, chunk.byteLength);
test.assertAnd(env.sto.currentIndex, 1, 'currentIndex');
test.assertAnd(env.sender.chunkSize, chunk.byteLength, 'chunkSize === byteLength');
// get payload
var payload = env.BDC.unpack(chunk)[2];
test.assert(env.sender.payloadSize, payload.byteLength);
test.assert(env.sender.payloadSize, payload.byteLength, 'payloadSize === byteLength');
}

@@ -78,3 +81,3 @@ },

env.sto.forEachChunk(function (chunk, pos) {
console.log('foreach [' + pos + '] ' + chunk.byteLength);
// console.log('foreach [' + pos + '] ' + chunk.byteLength);
if (pos < env.totalChunks - 1) {

@@ -81,0 +84,0 @@ test.assertAnd(chunk.byteLength, 16000);

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