1
Fork 0

work around issue with large files and maximum argument count limits

This commit is contained in:
Conduitry 2018-09-25 22:09:02 -04:00
parent e6e2876d86
commit 861a929f74
1 changed files with 2 additions and 2 deletions

View File

@ -30,14 +30,14 @@ const int = (n, length) => {
const toBytes = data => typeof data === 'string' ? [...data].map(char => char.charCodeAt(0)) : data;
export default files => {
const fileData = [];
let fileData = [];
const centralDirectory = [];
for (const { path, data } of files) {
const dataBytes = toBytes(data);
const pathBytes = toBytes(path);
const commonHeader = [0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ...int(crc32(dataBytes), 4), ...int(dataBytes.length, 4), ...int(dataBytes.length, 4), ...int(pathBytes.length, 2), 0x00, 0x00];
centralDirectory.push(0x50, 0x4B, 0x01, 0x02, 0x14, 0x00, ...commonHeader, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ...int(fileData.length, 4), ...pathBytes);
fileData.push(0x50, 0x4B, 0x03, 0x04, ...commonHeader, ...pathBytes, ...dataBytes);
fileData = [...fileData, 0x50, 0x4B, 0x03, 0x04, ...commonHeader, ...pathBytes, ...dataBytes];
}
const bytes = [...fileData, ...centralDirectory, 0x50, 0x4B, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, ...int(files.length, 2), ...int(files.length, 2), ...int(centralDirectory.length, 4), ...int(fileData.length, 4), 0x00, 0x00];
if (typeof Blob !== 'undefined' && typeof Uint8Array !== 'undefined') {