binary-data-chunking
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -979,3 +979,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){ | ||
checksum = SparkMD5.ArrayBuffer.hash(metadata.arrayBuffer); | ||
} | ||
} else { | ||
checksum = metadata.checksum; | ||
} | ||
@@ -1025,2 +1027,6 @@ this.uid = metadata.uid; | ||
BDC.prototype.getGeneratedChecksum = function () { | ||
return this._metadata.generatedChecksum; | ||
}; | ||
BDC.prototype.getFile = function (cb) { | ||
@@ -1032,4 +1038,4 @@ this._arrayBuffer = this._chunks[0]; | ||
} | ||
this._metadata.checksum = SparkMD5.ArrayBuffer.hash(this._arrayBuffer); | ||
cb(this._arrayBuffer, this._metadata.checksum); | ||
this._metadata.generatedChecksum = SparkMD5.ArrayBuffer.hash(this._arrayBuffer); | ||
cb(this._arrayBuffer, this._metadata.generatedChecksum); | ||
}; | ||
@@ -1036,0 +1042,0 @@ |
@@ -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(f,s){if(!r[f]){if(!t[f]){var a="function"==typeof require&&require;if(!s&&a)return a(f,!0);if(o)return o(f,!0);var u=new Error("Cannot find module '"+f+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[f]={exports:{}};t[f][0].call(h.exports,function(e){var r=t[f][1][e];return i(r?r:e)},h,h.exports,e,t,r,n)}return r[f].exports}for(var o="function"==typeof require&&require,f=0;f<n.length;f++)i(n[f]);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=v(v(e,t),v(n,o)),v(e<<i|e>>>32-i,r)}function r(t,r,n,i,o,f,s){return e(r&n|~r&i,t,r,o,f,s)}function n(t,r,n,i,o,f,s){return e(r&i|n&~i,t,r,o,f,s)}function i(t,r,n,i,o,f,s){return e(r^n^i,t,r,o,f,s)}function o(t,r,n,i,o,f,s){return e(n^(r|~i),t,r,o,f,s)}function f(t,e){var f=t[0],s=t[1],a=t[2],u=t[3];f=r(f,s,a,u,e[0],7,-680876936),u=r(u,f,s,a,e[1],12,-389564586),a=r(a,u,f,s,e[2],17,606105819),s=r(s,a,u,f,e[3],22,-1044525330),f=r(f,s,a,u,e[4],7,-176418897),u=r(u,f,s,a,e[5],12,1200080426),a=r(a,u,f,s,e[6],17,-1473231341),s=r(s,a,u,f,e[7],22,-45705983),f=r(f,s,a,u,e[8],7,1770035416),u=r(u,f,s,a,e[9],12,-1958414417),a=r(a,u,f,s,e[10],17,-42063),s=r(s,a,u,f,e[11],22,-1990404162),f=r(f,s,a,u,e[12],7,1804603682),u=r(u,f,s,a,e[13],12,-40341101),a=r(a,u,f,s,e[14],17,-1502002290),s=r(s,a,u,f,e[15],22,1236535329),f=n(f,s,a,u,e[1],5,-165796510),u=n(u,f,s,a,e[6],9,-1069501632),a=n(a,u,f,s,e[11],14,643717713),s=n(s,a,u,f,e[0],20,-373897302),f=n(f,s,a,u,e[5],5,-701558691),u=n(u,f,s,a,e[10],9,38016083),a=n(a,u,f,s,e[15],14,-660478335),s=n(s,a,u,f,e[4],20,-405537848),f=n(f,s,a,u,e[9],5,568446438),u=n(u,f,s,a,e[14],9,-1019803690),a=n(a,u,f,s,e[3],14,-187363961),s=n(s,a,u,f,e[8],20,1163531501),f=n(f,s,a,u,e[13],5,-1444681467),u=n(u,f,s,a,e[2],9,-51403784),a=n(a,u,f,s,e[7],14,1735328473),s=n(s,a,u,f,e[12],20,-1926607734),f=i(f,s,a,u,e[5],4,-378558),u=i(u,f,s,a,e[8],11,-2022574463),a=i(a,u,f,s,e[11],16,1839030562),s=i(s,a,u,f,e[14],23,-35309556),f=i(f,s,a,u,e[1],4,-1530992060),u=i(u,f,s,a,e[4],11,1272893353),a=i(a,u,f,s,e[7],16,-155497632),s=i(s,a,u,f,e[10],23,-1094730640),f=i(f,s,a,u,e[13],4,681279174),u=i(u,f,s,a,e[0],11,-358537222),a=i(a,u,f,s,e[3],16,-722521979),s=i(s,a,u,f,e[6],23,76029189),f=i(f,s,a,u,e[9],4,-640364487),u=i(u,f,s,a,e[12],11,-421815835),a=i(a,u,f,s,e[15],16,530742520),s=i(s,a,u,f,e[2],23,-995338651),f=o(f,s,a,u,e[0],6,-198630844),u=o(u,f,s,a,e[7],10,1126891415),a=o(a,u,f,s,e[14],15,-1416354905),s=o(s,a,u,f,e[5],21,-57434055),f=o(f,s,a,u,e[12],6,1700485571),u=o(u,f,s,a,e[3],10,-1894986606),a=o(a,u,f,s,e[10],15,-1051523),s=o(s,a,u,f,e[1],21,-2054922799),f=o(f,s,a,u,e[8],6,1873313359),u=o(u,f,s,a,e[15],10,-30611744),a=o(a,u,f,s,e[6],15,-1560198380),s=o(s,a,u,f,e[13],21,1309151649),f=o(f,s,a,u,e[4],6,-145523070),u=o(u,f,s,a,e[11],10,-1120210379),a=o(a,u,f,s,e[2],15,718787259),s=o(s,a,u,f,e[9],21,-343485551),t[0]=v(f,t[0]),t[1]=v(s,t[1]),t[2]=v(a,t[2]),t[3]=v(u,t[3])}function s(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 a(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,a,u=t.length,h=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)f(h,s(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(f(h,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),a=parseInt(i[1],16)||0,n[14]=o,n[15]=a,f(h,n),h}function h(t){var e,r,n,i,o,s,u=t.length,h=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)f(h,a(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(f(h,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),s=parseInt(i[1],16)||0,n[14]=o,n[15]=s,f(h,n),h}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 _(t){return String.fromCharCode.apply(null,new Uint8Array(t))}function l(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 m(){this.reset()}var v=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"))&&(v=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,f,s,a=this.byteLength,u=e(r,a),h=a;return n!==t&&(h=e(n,a)),u>h?new ArrayBuffer(0):(i=h-u,o=new ArrayBuffer(i),f=new Uint8Array(o),s=new Uint8Array(this,u,i),f.set(s),o)}}(),m.prototype.append=function(t){return this.appendBinary(y(t)),this},m.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var e,r=this._buff.length;for(e=64;r>=e;e+=64)f(this._hash,s(this._buff.substring(e-64,e)));return this._buff=this._buff.substring(e-64),this},m.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},m.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},m.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(t,e){var r,n,i,o=e;if(t[o>>2]|=128<<(o%4<<3),o>55)for(f(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,f(this._hash,t)},m.hash=function(t,e){return m.hashBinary(y(t),e)},m.hashBinary=function(t,e){var r=u(t),n=p(r);return e?g(n):n},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(t){var e,r=l(this._buff.buffer,t,!0),n=r.length;for(this._length+=t.byteLength,e=64;n>=e;e+=64)f(this._hash,a(r.subarray(e-64,e)));return this._buff=n>e-64?new Uint8Array(r.buffer.slice(e-64)):new Uint8Array(0),this},m.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},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var t=m.prototype.getState.call(this);return t.buff=_(t.buff),t},m.ArrayBuffer.prototype.setState=function(t){return t.buff=d(t.buff,!0),m.prototype.setState.call(this,t)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(t,e){var r=h(new Uint8Array(t)),n=p(r);return e?g(n):n},m})},{}],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,f=n.length;f>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;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-a,e=Math.ceil(t.arrayBuffer.byteLength/r),i=s.ArrayBuffer.hash(t.arrayBuffer)),this.uid=t.uid,this._metadata={uid:t.uid,name:t.name,mimeType:t.mimeType,chunkSize:t.chunkSize,payloadSize:r,reservedSize:a,fileSize:t.arrayBuffer?t.arrayBuffer.byteLength:0,totalChunks:e?e:t.totalChunks?t.totalChunks:0,checksum:i},this._arrayBuffer=t.arrayBuffer?t.arrayBuffer:null,this._chunksProcessed=0,this._chunks=[],t.arrayBuffer||c.addRecord(this)}var f=t("array-keys"),s=t("spark-md5"),a=8,u=0,h=4,c=new f({identifier:"uid"});o.prototype.getMetadata=function(){return this._metadata},o.prototype.getUID=function(){return this.uid},o.prototype.getFileSize=function(){return this._metadata.fileSize},o.prototype.getTotalChunks=function(){return this._metadata.totalChunks},o.prototype.getChecksum=function(){return this._metadata.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._metadata.checksum=s.ArrayBuffer.hash(this._arrayBuffer),t(this._arrayBuffer,this._metadata.checksum)},o.prototype.onChunkReceived=function(){},o.prototype.onCompleted=function(){},o.prototype.getPosition=function(){return this._chunksProcessed},o.prototype.forEachChunk=function(t,e){for(var r,n=0;n<this._metadata.totalChunks;n+=1)(r=this.getChunk())?t(r,this.getPosition()):e()},o.prototype.getChunk=function(t){var e=this._chunksProcessed+1;if("number"==typeof t){if(0>=t)return;e=t}else t=void 0;var r=this._metadata.payloadSize*e-this._metadata.payloadSize;if(!(r>=this._metadata.fileSize)){var n=r+this._metadata.payloadSize;n=n>this._metadata.fileSize?this._metadata.fileSize:n;var i=this._arrayBuffer.slice(r,n),f=o.__pack(this._metadata.uid,e,i);return t||(this._chunksProcessed+=1),f}},o.prototype.clearData=function(){c.removeRecord(this.uid),delete this._arrayBuffer,delete this._metadata,delete this},o.__pack=function(t,e,r){var n=new ArrayBuffer(r.byteLength+a),i=new DataView(n);return i.setInt32(u,t),i.setInt32(h,e),new Uint8Array(n,0,n.byteLength).set(new Uint8Array(r),a),n},o.__unpack=function(t){var e=new DataView(t),r=e.getInt32(u),n=e.getInt32(h),i=new Uint8Array(t.slice(a));return[r,n,i]},o.submitChunk=function(t){var e=this.__unpack(t),r=e[0],n=e[1],i=e[2],o=c.getRecord(r);return o?(o._chunks[n-1]=i,o._chunksProcessed+=1,o.onChunkReceived(i,n),o.getPosition()===o.getTotalChunks()&&o.onCompleted(),c.addRecord(o),!0):!1},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(f,s){if(!r[f]){if(!t[f]){var a="function"==typeof require&&require;if(!s&&a)return a(f,!0);if(o)return o(f,!0);var u=new Error("Cannot find module '"+f+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[f]={exports:{}};t[f][0].call(h.exports,function(e){var r=t[f][1][e];return i(r?r:e)},h,h.exports,e,t,r,n)}return r[f].exports}for(var o="function"==typeof require&&require,f=0;f<n.length;f++)i(n[f]);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=v(v(e,t),v(n,o)),v(e<<i|e>>>32-i,r)}function r(t,r,n,i,o,f,s){return e(r&n|~r&i,t,r,o,f,s)}function n(t,r,n,i,o,f,s){return e(r&i|n&~i,t,r,o,f,s)}function i(t,r,n,i,o,f,s){return e(r^n^i,t,r,o,f,s)}function o(t,r,n,i,o,f,s){return e(n^(r|~i),t,r,o,f,s)}function f(t,e){var f=t[0],s=t[1],a=t[2],u=t[3];f=r(f,s,a,u,e[0],7,-680876936),u=r(u,f,s,a,e[1],12,-389564586),a=r(a,u,f,s,e[2],17,606105819),s=r(s,a,u,f,e[3],22,-1044525330),f=r(f,s,a,u,e[4],7,-176418897),u=r(u,f,s,a,e[5],12,1200080426),a=r(a,u,f,s,e[6],17,-1473231341),s=r(s,a,u,f,e[7],22,-45705983),f=r(f,s,a,u,e[8],7,1770035416),u=r(u,f,s,a,e[9],12,-1958414417),a=r(a,u,f,s,e[10],17,-42063),s=r(s,a,u,f,e[11],22,-1990404162),f=r(f,s,a,u,e[12],7,1804603682),u=r(u,f,s,a,e[13],12,-40341101),a=r(a,u,f,s,e[14],17,-1502002290),s=r(s,a,u,f,e[15],22,1236535329),f=n(f,s,a,u,e[1],5,-165796510),u=n(u,f,s,a,e[6],9,-1069501632),a=n(a,u,f,s,e[11],14,643717713),s=n(s,a,u,f,e[0],20,-373897302),f=n(f,s,a,u,e[5],5,-701558691),u=n(u,f,s,a,e[10],9,38016083),a=n(a,u,f,s,e[15],14,-660478335),s=n(s,a,u,f,e[4],20,-405537848),f=n(f,s,a,u,e[9],5,568446438),u=n(u,f,s,a,e[14],9,-1019803690),a=n(a,u,f,s,e[3],14,-187363961),s=n(s,a,u,f,e[8],20,1163531501),f=n(f,s,a,u,e[13],5,-1444681467),u=n(u,f,s,a,e[2],9,-51403784),a=n(a,u,f,s,e[7],14,1735328473),s=n(s,a,u,f,e[12],20,-1926607734),f=i(f,s,a,u,e[5],4,-378558),u=i(u,f,s,a,e[8],11,-2022574463),a=i(a,u,f,s,e[11],16,1839030562),s=i(s,a,u,f,e[14],23,-35309556),f=i(f,s,a,u,e[1],4,-1530992060),u=i(u,f,s,a,e[4],11,1272893353),a=i(a,u,f,s,e[7],16,-155497632),s=i(s,a,u,f,e[10],23,-1094730640),f=i(f,s,a,u,e[13],4,681279174),u=i(u,f,s,a,e[0],11,-358537222),a=i(a,u,f,s,e[3],16,-722521979),s=i(s,a,u,f,e[6],23,76029189),f=i(f,s,a,u,e[9],4,-640364487),u=i(u,f,s,a,e[12],11,-421815835),a=i(a,u,f,s,e[15],16,530742520),s=i(s,a,u,f,e[2],23,-995338651),f=o(f,s,a,u,e[0],6,-198630844),u=o(u,f,s,a,e[7],10,1126891415),a=o(a,u,f,s,e[14],15,-1416354905),s=o(s,a,u,f,e[5],21,-57434055),f=o(f,s,a,u,e[12],6,1700485571),u=o(u,f,s,a,e[3],10,-1894986606),a=o(a,u,f,s,e[10],15,-1051523),s=o(s,a,u,f,e[1],21,-2054922799),f=o(f,s,a,u,e[8],6,1873313359),u=o(u,f,s,a,e[15],10,-30611744),a=o(a,u,f,s,e[6],15,-1560198380),s=o(s,a,u,f,e[13],21,1309151649),f=o(f,s,a,u,e[4],6,-145523070),u=o(u,f,s,a,e[11],10,-1120210379),a=o(a,u,f,s,e[2],15,718787259),s=o(s,a,u,f,e[9],21,-343485551),t[0]=v(f,t[0]),t[1]=v(s,t[1]),t[2]=v(a,t[2]),t[3]=v(u,t[3])}function s(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 a(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,a,u=t.length,h=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)f(h,s(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(f(h,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),a=parseInt(i[1],16)||0,n[14]=o,n[15]=a,f(h,n),h}function h(t){var e,r,n,i,o,s,u=t.length,h=[1732584193,-271733879,-1732584194,271733878];for(e=64;u>=e;e+=64)f(h,a(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(f(h,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),s=parseInt(i[1],16)||0,n[14]=o,n[15]=s,f(h,n),h}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 _(t){return String.fromCharCode.apply(null,new Uint8Array(t))}function l(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 m(){this.reset()}var v=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"))&&(v=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,f,s,a=this.byteLength,u=e(r,a),h=a;return n!==t&&(h=e(n,a)),u>h?new ArrayBuffer(0):(i=h-u,o=new ArrayBuffer(i),f=new Uint8Array(o),s=new Uint8Array(this,u,i),f.set(s),o)}}(),m.prototype.append=function(t){return this.appendBinary(y(t)),this},m.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var e,r=this._buff.length;for(e=64;r>=e;e+=64)f(this._hash,s(this._buff.substring(e-64,e)));return this._buff=this._buff.substring(e-64),this},m.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},m.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},m.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(t,e){var r,n,i,o=e;if(t[o>>2]|=128<<(o%4<<3),o>55)for(f(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,f(this._hash,t)},m.hash=function(t,e){return m.hashBinary(y(t),e)},m.hashBinary=function(t,e){var r=u(t),n=p(r);return e?g(n):n},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(t){var e,r=l(this._buff.buffer,t,!0),n=r.length;for(this._length+=t.byteLength,e=64;n>=e;e+=64)f(this._hash,a(r.subarray(e-64,e)));return this._buff=n>e-64?new Uint8Array(r.buffer.slice(e-64)):new Uint8Array(0),this},m.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},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var t=m.prototype.getState.call(this);return t.buff=_(t.buff),t},m.ArrayBuffer.prototype.setState=function(t){return t.buff=d(t.buff,!0),m.prototype.setState.call(this,t)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(t,e){var r=h(new Uint8Array(t)),n=p(r);return e?g(n):n},m})},{}],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,f=n.length;f>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;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-a,e=Math.ceil(t.arrayBuffer.byteLength/r),i=s.ArrayBuffer.hash(t.arrayBuffer)):i=t.checksum,this.uid=t.uid,this._metadata={uid:t.uid,name:t.name,mimeType:t.mimeType,chunkSize:t.chunkSize,payloadSize:r,reservedSize:a,fileSize:t.arrayBuffer?t.arrayBuffer.byteLength:0,totalChunks:e?e:t.totalChunks?t.totalChunks:0,checksum:i},this._arrayBuffer=t.arrayBuffer?t.arrayBuffer:null,this._chunksProcessed=0,this._chunks=[],t.arrayBuffer||c.addRecord(this)}var f=t("array-keys"),s=t("spark-md5"),a=8,u=0,h=4,c=new f({identifier:"uid"});o.prototype.getMetadata=function(){return this._metadata},o.prototype.getUID=function(){return this.uid},o.prototype.getFileSize=function(){return this._metadata.fileSize},o.prototype.getTotalChunks=function(){return this._metadata.totalChunks},o.prototype.getChecksum=function(){return this._metadata.checksum},o.prototype.getGeneratedChecksum=function(){return this._metadata.generatedChecksum},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._metadata.generatedChecksum=s.ArrayBuffer.hash(this._arrayBuffer),t(this._arrayBuffer,this._metadata.generatedChecksum)},o.prototype.onChunkReceived=function(){},o.prototype.onCompleted=function(){},o.prototype.getPosition=function(){return this._chunksProcessed},o.prototype.forEachChunk=function(t,e){for(var r,n=0;n<this._metadata.totalChunks;n+=1)(r=this.getChunk())?t(r,this.getPosition()):e()},o.prototype.getChunk=function(t){var e=this._chunksProcessed+1;if("number"==typeof t){if(0>=t)return;e=t}else t=void 0;var r=this._metadata.payloadSize*e-this._metadata.payloadSize;if(!(r>=this._metadata.fileSize)){var n=r+this._metadata.payloadSize;n=n>this._metadata.fileSize?this._metadata.fileSize:n;var i=this._arrayBuffer.slice(r,n),f=o.__pack(this._metadata.uid,e,i);return t||(this._chunksProcessed+=1),f}},o.prototype.clearData=function(){c.removeRecord(this.uid),delete this._arrayBuffer,delete this._metadata,delete this},o.__pack=function(t,e,r){var n=new ArrayBuffer(r.byteLength+a),i=new DataView(n);return i.setInt32(u,t),i.setInt32(h,e),new Uint8Array(n,0,n.byteLength).set(new Uint8Array(r),a),n},o.__unpack=function(t){var e=new DataView(t),r=e.getInt32(u),n=e.getInt32(h),i=new Uint8Array(t.slice(a));return[r,n,i]},o.submitChunk=function(t){var e=this.__unpack(t),r=e[0],n=e[1],i=e[2],o=c.getRecord(r);return o?(o._chunks[n-1]=i,o._chunksProcessed+=1,o.onChunkReceived(i,n),o.getPosition()===o.getTotalChunks()&&o.onCompleted(),c.addRecord(o),!0):!1},e.exports=o},{"array-keys":1,"spark-md5":2}]},{},[4])(4)}); |
{ | ||
"name": "binary-data-chunking", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A small library that simplifies sending large amounts of chunked binary data", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -48,3 +48,5 @@ var ArrayKeys = require('array-keys'); | ||
checksum = SparkMD5.ArrayBuffer.hash(metadata.arrayBuffer); | ||
} | ||
} else { | ||
checksum = metadata.checksum; | ||
} | ||
@@ -94,2 +96,6 @@ this.uid = metadata.uid; | ||
BDC.prototype.getGeneratedChecksum = function () { | ||
return this._metadata.generatedChecksum; | ||
}; | ||
BDC.prototype.getFile = function (cb) { | ||
@@ -101,4 +107,4 @@ this._arrayBuffer = this._chunks[0]; | ||
} | ||
this._metadata.checksum = SparkMD5.ArrayBuffer.hash(this._arrayBuffer); | ||
cb(this._arrayBuffer, this._metadata.checksum); | ||
this._metadata.generatedChecksum = SparkMD5.ArrayBuffer.hash(this._arrayBuffer); | ||
cb(this._arrayBuffer, this._metadata.generatedChecksum); | ||
}; | ||
@@ -105,0 +111,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1122633
1305