Skip to content

Commit

Permalink
write AES and custom extra field in the local header (fix #227)
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed Mar 11, 2021
1 parent ed21d97 commit 6a74f00
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/core/zip-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,14 @@ async function createFileEntry(reader, writer, config, options) {
setUint32(headerView, 6, rawLastModDate);
setUint16(headerView, 22, rawFilename.length);
setUint16(headerView, 24, 0);
const fileDataArray = new Uint8Array(30 + rawFilename.length);
const fileDataView = new DataView(fileDataArray.buffer);
setUint32(fileDataView, 0, LOCAL_FILE_HEADER_SIGNATURE);
fileDataArray.set(headerArray, 4);
fileDataArray.set(rawFilename, 30);
setUint16(headerView, 24, rawExtraFieldAES.length + fileEntry.rawExtraField.length);
const footerArray = new Uint8Array(30 + rawFilename.length + rawExtraFieldAES.length + fileEntry.rawExtraField.length);
const footerView = new DataView(footerArray.buffer);
setUint32(footerView, 0, LOCAL_FILE_HEADER_SIGNATURE);
footerArray.set(headerArray, 4);
footerArray.set(rawFilename, 30);
footerArray.set(rawExtraFieldAES, 30 + rawFilename.length);
footerArray.set(fileEntry.rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length);
let result;
let uncompressedSize = 0;
let compressedSize = 0;
Expand All @@ -435,11 +438,11 @@ async function createFileEntry(reader, writer, config, options) {
encrypted,
useWebWorkers: options.useWebWorkers
}, config);
await writer.writeUint8Array(fileDataArray);
await writer.writeUint8Array(footerArray);
result = await processData(codec, reader, writer, 0, uncompressedSize, config, { onprogress: options.onprogress, signal: options.signal });
compressedSize = result.length;
} else {
await writer.writeUint8Array(fileDataArray);
await writer.writeUint8Array(footerArray);
}
let dataDescriptorArray = new Uint8Array(0);
let dataDescriptorView;
Expand Down Expand Up @@ -480,7 +483,7 @@ async function createFileEntry(reader, writer, config, options) {
if (options.dataDescriptor) {
await writer.writeUint8Array(dataDescriptorArray);
}
const length = fileDataArray.length + (result ? result.length : 0) + dataDescriptorArray.length;
const length = footerArray.length + (result ? result.length : 0) + dataDescriptorArray.length;
Object.assign(fileEntry, { compressedSize, uncompressedSize, lastModDate, rawLastModDate, encrypted, length });
return fileEntry;
}
Expand Down

0 comments on commit 6a74f00

Please sign in to comment.