File tree Expand file tree Collapse file tree 5 files changed +38
-3
lines changed
packages/middleware-flexible-checksums Expand file tree Collapse file tree 5 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 17
17
"main" : " ./dist-cjs/index.js" ,
18
18
"module" : " ./dist-es/index.js" ,
19
19
"browser" : {
20
+ "./dist-es/getCrc32ChecksumAlgorithmFunction" : " ./dist-es/getCrc32ChecksumAlgorithmFunction.browser" ,
20
21
"./dist-es/streams/create-read-stream-on-buffer" : " ./dist-es/streams/create-read-stream-on-buffer.browser"
21
22
},
22
23
"react-native" : {
24
+ "./dist-es/getCrc32ChecksumAlgorithmFunction" : " ./dist-es/getCrc32ChecksumAlgorithmFunction.browser" ,
23
25
"./dist-es/streams/create-read-stream-on-buffer" : " ./dist-es/streams/create-read-stream-on-buffer.browser" ,
26
+ "./dist-cjs/getCrc32ChecksumAlgorithmFunction" : " ./dist-cjs/getCrc32ChecksumAlgorithmFunction.browser" ,
24
27
"./dist-cjs/streams/create-read-stream-on-buffer" : " ./dist-cjs/streams/create-read-stream-on-buffer.browser"
25
28
},
26
29
"types" : " ./dist-types/index.d.ts" ,
32
35
"dependencies" : {
33
36
"@aws-crypto/crc32" : " 5.2.0" ,
34
37
"@aws-crypto/crc32c" : " 5.2.0" ,
38
+ "@aws-crypto/util" : " 5.2.0" ,
35
39
"@aws-sdk/core" : " *" ,
36
40
"@aws-sdk/types" : " *" ,
37
41
"@smithy/is-array-buffer" : " ^3.0.0" ,
Original file line number Diff line number Diff line change
1
+ import { AwsCrc32 } from "@aws-crypto/crc32" ;
2
+
3
+ export const getCrc32ChecksumAlgorithmFunction = ( ) => AwsCrc32 ;
Original file line number Diff line number Diff line change
1
+ import { AwsCrc32 } from "@aws-crypto/crc32" ;
2
+ import { numToUint8 } from "@aws-crypto/util" ;
3
+ import { Checksum } from "@smithy/types" ;
4
+ import zlib from "zlib" ;
5
+
6
+ export const getCrc32ChecksumAlgorithmFunction = ( ) => {
7
+ // @ts -expect-error crc32 is defined only for Node.js >v20.15.0+ and >v22.2.0+.
8
+ if ( typeof zlib . crc32 === "undefined" ) {
9
+ return AwsCrc32 ;
10
+ }
11
+
12
+ return class NodeCrc32 implements Checksum {
13
+ private 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
+ } ;
28
+ } ;
Original file line number Diff line number Diff line change 1
- import { AwsCrc32 } from "@aws-crypto/crc32" ;
2
1
import { AwsCrc32c } from "@aws-crypto/crc32c" ;
3
2
import { ChecksumConstructor , HashConstructor } from "@smithy/types" ;
4
3
5
4
import { PreviouslyResolved } from "./configuration" ;
6
5
import { ChecksumAlgorithm } from "./constants" ;
6
+ import { getCrc32ChecksumAlgorithmFunction } from "./getCrc32ChecksumAlgorithmFunction" ;
7
7
8
8
/**
9
9
* Returns the function that will compute the checksum for the given {@link ChecksumAlgorithm}.
@@ -14,7 +14,7 @@ export const selectChecksumAlgorithmFunction = (
14
14
) : ChecksumConstructor | HashConstructor =>
15
15
( {
16
16
[ ChecksumAlgorithm . MD5 ] : config . md5 ,
17
- [ ChecksumAlgorithm . CRC32 ] : AwsCrc32 ,
17
+ [ ChecksumAlgorithm . CRC32 ] : getCrc32ChecksumAlgorithmFunction ( ) ,
18
18
[ ChecksumAlgorithm . CRC32C ] : AwsCrc32c ,
19
19
[ ChecksumAlgorithm . SHA1 ] : config . sha1 ,
20
20
[ ChecksumAlgorithm . SHA256 ] : config . sha256 ,
Original file line number Diff line number Diff line change 74
74
dependencies :
75
75
tslib "^2.6.2"
76
76
77
- " @aws-crypto/util@^5.2.0 " :
77
+ " @aws-crypto/util@5.2.0 " , "@aws-crypto/util@ ^5.2.0":
78
78
version "5.2.0"
79
79
resolved "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz"
80
80
integrity sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==
You can’t perform that action at this time.
0 commit comments