Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zip): cd header and zip64 info generation implemented #2792

Merged
merged 6 commits into from
Nov 21, 2023

Conversation

dariaterekhova-actionengine
Copy link
Collaborator

Part of changes I'll need in order to create slpk with hash file inside

Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added suggestions for aligning coding style with loaders.gl norms. I can see that you prefer a different, arguably more modern style. While there is no "right" style, there is some value in being consistent across a big code base.

@@ -0,0 +1,96 @@
export const signature = new Uint8Array([0x01, 0x00]);

/** info that can be placed into zip64 field */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link to some specification in the comment?

* @param options info that can be placed into zip64 field
* @returns buffer with field
*/
export const createZip64Info = (options: Zip64Options): ArrayBuffer => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Prefer function syntax for longer functions. IIMHO, the => arrow notation is best for callbacks and one liners.,

Suggested change
export const createZip64Info = (options: Zip64Options): ArrayBuffer => {
export function createZip64Info(options: Zip64Options): ArrayBuffer {


let result = new ArrayBuffer(0);

zip64Fields.forEach((field) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Prefer for loops:

Suggested change
zip64Fields.forEach((field) => {
for (field of zip64Fields) {

zip64Length: (options.offset ? 1 : 0) * 8 + (options.size ? 1 : 0) * 16
};

let result = new ArrayBuffer(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated concatenation is expensive (you end up copying the same data over and over again). Better to save an array of chunks and concatenate at the end.

Suggested change
let result = new ArrayBuffer(0);
const chunks: ArrayBuffer[] = [];
...
return concatenateArrayBuffers(chunks);

}
const newValue = new DataView(new ArrayBuffer(field.size));
setNumbers[field.size](newValue, 0, optionsToUse[field.name ?? ''] ?? field.default);
result = concatArrays(result, newValue.buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agan, avoid repeated concatenation...


const encodedName = new TextEncoder().encode(optionsToUse.fileName);

const resHeader = concatArrays(concatArrays(header.buffer, encodedName), zip64header);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import from loaders.gl/loader-utils, see comment below.

}
const header = new DataView(new ArrayBuffer(46));

fields.forEach((field) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use for loop, see comment below

Comment on lines +229 to +232
if (Object.keys(optionsToZip64).length) {
zip64header = createZip64Info(optionsToZip64);
optionsToUse.extraLength = zip64header.byteLength;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can have this function return null if no keys, rather than check length of keys here?

Suggested change
if (Object.keys(optionsToZip64).length) {
zip64header = createZip64Info(optionsToZip64);
optionsToUse.extraLength = zip64header.byteLength;
}
const zip64header = createZip64Info(optionsToZip64);
if (zip64Header) {
optionsToUse.extraLength = zip64header.byteLength;
}

* @param options info that can be placed into cd header
* @returns buffer with header
*/
export const generateCdHeader = (options: CDGenOptions): ArrayBuffer => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Use function keywors
  • I recommend preserving capitalization rather than decapitalizing to fit the camelCase.
  • Also be consistent with function names and option types
Suggested change
export const generateCdHeader = (options: CDGenOptions): ArrayBuffer => {
export function generateCDHeader(options: GenerateCDOptions): ArrayBuffer {

@@ -188,3 +189,167 @@ const findExpectedData = (zip64data: Zip64Data): {length: number; name: string}[

return zip64dataList;
};

/** info that can be placed into cd header */
type CDGenOptions = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenerateCDOptions?

@belom88 belom88 changed the base branch from master to 4.1-dev November 20, 2023 12:23
@dariaterekhova-actionengine dariaterekhova-actionengine merged commit d1cf361 into 4.1-dev Nov 21, 2023
@dariaterekhova-actionengine dariaterekhova-actionengine deleted the dt/cd_header_generation branch November 21, 2023 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants