Last active
August 29, 2015 14:08
-
-
Save nahidakbar/b3c26ddeb1f36c3f82ae to your computer and use it in GitHub Desktop.
ArrayBufferWriter for zip.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @class custom Writer; zipjs one breaks in chrome for large binary files | |
*/ | |
function ArrayBufferWriter(contentSize, filename) | |
{ | |
var output, that = this, offset, errored; | |
function init(callback) | |
{ | |
output = new Uint8Array(contentSize); | |
offset = 0; | |
errored = false; | |
callback(); | |
} | |
function writeUint8Array(array, callback) | |
{ | |
if (!errored) | |
{ | |
if (array.length) | |
{ | |
output.set(array, offset); | |
offset += array.length; | |
} else | |
{ | |
showError(filename + ' decompresstion error. Content will be trimmed to current position. All elements may not work as expected as a result.'); | |
errored = true; | |
output = output.subarray(0, offset); | |
} | |
} | |
callback(); | |
} | |
function getData(callback) | |
{ | |
callback(output.buffer); | |
} | |
that.init = init; | |
that.writeUint8Array = writeUint8Array; | |
that.getData = getData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are problems with it in inferior systems like windows such as not being able to allocate a large block of data.