Skip to content

Commit 17b37b7

Browse files
authored
chore(middleware-flexible-checksums): move inline class NodeCrc32 outside (#6648)
1 parent b2fb10a commit 17b37b7

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

Diff for: packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ import { numToUint8 } from "@aws-crypto/util";
33
import { Checksum } from "@smithy/types";
44
import * as zlib from "zlib";
55

6+
class NodeCrc32 implements Checksum {
7+
private checksum = 0;
8+
9+
update(data: Uint8Array) {
10+
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
11+
this.checksum = zlib.crc32(data, this.checksum);
12+
}
13+
14+
async digest() {
15+
return numToUint8(this.checksum);
16+
}
17+
18+
reset() {
19+
this.checksum = 0;
20+
}
21+
}
22+
623
export const getCrc32ChecksumAlgorithmFunction = () => {
724
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
825
if (typeof zlib.crc32 === "undefined") {
926
return AwsCrc32;
1027
}
1128

12-
return class NodeCrc32 implements Checksum {
13-
checksum = 0;
14-
15-
update(data: Uint8Array) {
16-
// @ts-expect-error crc32 is defined only for Node.js >=v20.15.0 and >=v22.2.0.
17-
this.checksum = zlib.crc32(data, this.checksum);
18-
}
19-
20-
async digest() {
21-
return numToUint8(this.checksum);
22-
}
23-
24-
reset() {
25-
this.checksum = 0;
26-
}
27-
};
29+
return NodeCrc32;
2830
};

Diff for: packages/middleware-flexible-checksums/src/selectChecksumAlgorithmFunction.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AwsCrc32c } from "@aws-crypto/crc32c";
22
import { describe, expect, test as it, vi } from "vitest";
33

44
import { ChecksumAlgorithm } from "./constants";
5-
// import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
5+
import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction";
66
import { selectChecksumAlgorithmFunction } from "./selectChecksumAlgorithmFunction";
77

88
describe(selectChecksumAlgorithmFunction.name, () => {
@@ -14,7 +14,7 @@ describe(selectChecksumAlgorithmFunction.name, () => {
1414

1515
it.each([
1616
[ChecksumAlgorithm.MD5, mockConfig.md5],
17-
// [ChecksumAlgorithm.CRC32, getCrc32ChecksumAlgorithmFunction()],
17+
[ChecksumAlgorithm.CRC32, getCrc32ChecksumAlgorithmFunction()],
1818
[ChecksumAlgorithm.CRC32C, AwsCrc32c],
1919
[ChecksumAlgorithm.SHA1, mockConfig.sha1],
2020
[ChecksumAlgorithm.SHA256, mockConfig.sha256],

0 commit comments

Comments
 (0)