Skip to content

Commit 5f49547

Browse files
authored
fix(crc32c): ie11 does not support Array.from (#221)
1 parent e94b726 commit 5f49547

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

packages/crc32/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {uint32ArrayFrom} from "@aws-crypto/util";
2+
13
export function crc32(data: Uint8Array): number {
24
return new Crc32().update(data).digest();
35
}
@@ -20,7 +22,7 @@ export class Crc32 {
2022
}
2123

2224
// prettier-ignore
23-
const lookupTable = Uint32Array.from([
25+
const a_lookUpTable = [
2426
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
2527
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
2628
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
@@ -85,6 +87,6 @@ const lookupTable = Uint32Array.from([
8587
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
8688
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
8789
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
88-
]);
89-
90+
];
91+
const lookupTable: Uint32Array = uint32ArrayFrom(a_lookUpTable)
9092
export { AwsCrc32 } from "./aws_crc32";

packages/crc32c/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import {uint32ArrayFrom} from "@aws-crypto/util";
5+
16
export function crc32c(data: Uint8Array): number {
27
return new Crc32c().update(data).digest();
38
}
@@ -20,7 +25,7 @@ export class Crc32c {
2025
}
2126

2227
// prettier-ignore
23-
const lookupTable = Uint32Array.from([
28+
const a_lookupTable = [
2429
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
2530
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
2631
0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B, 0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384,
@@ -53,6 +58,7 @@ const lookupTable = Uint32Array.from([
5358
0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321, 0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E,
5459
0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E,
5560
0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351,
56-
]);
61+
];
5762

63+
const lookupTable: Uint32Array = uint32ArrayFrom(a_lookupTable)
5864
export { AwsCrc32c } from "./aws_crc32c";

packages/util/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
export { convertToBuffer } from "./convertToBuffer";
55
export { isEmptyData } from "./isEmptyData";
66
export { numToUint8 } from "./numToUint8";
7+
export {uint32ArrayFrom} from './uint32ArrayFrom';

packages/util/src/uint32ArrayFrom.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// IE 11 does not support Array.from, so we do it manually
5+
export function uint32ArrayFrom(a_lookUpTable: Array<number>): Uint32Array {
6+
if (!Array.from) {
7+
const return_array = new Uint32Array(a_lookUpTable.length)
8+
let a_index = 0
9+
while (a_index < a_lookUpTable.length) {
10+
return_array[a_index] = a_lookUpTable[a_index]
11+
}
12+
return return_array
13+
}
14+
return Uint32Array.from(a_lookUpTable)
15+
}

0 commit comments

Comments
 (0)