Skip to content

Instantly share code, notes, and snippets.

@nahidakbar
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahidakbar/b3c26ddeb1f36c3f82ae to your computer and use it in GitHub Desktop.
Save nahidakbar/b3c26ddeb1f36c3f82ae to your computer and use it in GitHub Desktop.
ArrayBufferWriter for zip.js
/**
* @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;
}
@nahidakbar
Copy link
Author

There are problems with it in inferior systems like windows such as not being able to allocate a large block of data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment