Skip to content

Commit 6a3a627

Browse files
committed
chore(middleware-flexible-checksums): move inline class NodeCrc32 outside
1 parent b2fb10a commit 6a3a627

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts

Lines changed: 18 additions & 16 deletions
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+
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
};

0 commit comments

Comments
 (0)