Skip to content

Commit

Permalink
concatenateArrayBuffers fix (#2856)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariaterekhova-actionengine authored Jan 16, 2024
1 parent 2243c12 commit 17f79e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/loader-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export {parseJSON} from './lib/parser-utils/parse-json';
export {
sliceArrayBuffer,
concatenateArrayBuffers,
concatenateArrayBuffersFromArray,
concatenateTypedArrays,
compareArrayBuffers
} from './lib/binary-utils/array-buffer-utils';
Expand Down
12 changes: 10 additions & 2 deletions modules/loader-utils/src/lib/binary-utils/array-buffer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ export function compareArrayBuffers(
}

/**
* Concatenate a sequence of ArrayBuffers
* Concatenate a sequence of ArrayBuffers from arguments
* @return A concatenated ArrayBuffer
*/
export function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {
export function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): any {
return concatenateArrayBuffersFromArray(sources);
}

/**
* Concatenate a sequence of ArrayBuffers from array
* @return A concatenated ArrayBuffer
*/
export function concatenateArrayBuffersFromArray(sources: (ArrayBuffer | Uint8Array)[]): any {
// Make sure all inputs are wrapped in typed arrays
const sourceArrays = sources.map((source2) =>
source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
Expand Down
8 changes: 6 additions & 2 deletions modules/zip/src/hash-file-utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// Copyright (c) vis.gl contributors

import {MD5Hash} from '@loaders.gl/crypto';
import {FileProvider, concatenateArrayBuffers} from '@loaders.gl/loader-utils';
import {
FileProvider,
concatenateArrayBuffers,
concatenateArrayBuffersFromArray
} from '@loaders.gl/loader-utils';
import {makeZipCDHeaderIterator} from './parse-zip/cd-file-header';

/**
Expand Down Expand Up @@ -66,7 +70,7 @@ export async function composeHashFile(fileProvider: FileProvider): Promise<Array
const bufferArray = Object.entries(hashArray)
.map(([key, value]) => concatenateArrayBuffers(hexStringToBuffer(key), bigintToBuffer(value)))
.sort(compareHashes);
return concatenateArrayBuffers(...bufferArray);
return concatenateArrayBuffersFromArray(bufferArray);
}

/**
Expand Down

0 comments on commit 17f79e9

Please sign in to comment.