WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bcf8e23

Browse files
committed
feat: deprecate composite checksum
1 parent ac6aaff commit bcf8e23

File tree

12 files changed

+40
-409
lines changed

12 files changed

+40
-409
lines changed

packages/storage/__tests__/providers/s3/apis/internal/uploadData/multipartHandlers.test.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ const getZeroDelayTimeout = () =>
7575

7676
const mockCalculateContentCRC32Mock = () => {
7777
mockCalculateContentCRC32.mockReset();
78-
mockCalculateContentCRC32.mockResolvedValue({
79-
checksumArrayBuffer: new ArrayBuffer(0),
80-
checksum: 'mockChecksum',
81-
seed: 0,
82-
});
78+
mockCalculateContentCRC32.mockResolvedValue('mockChecksum');
8379
};
8480
const mockCalculateContentCRC32Reset = () => {
8581
mockCalculateContentCRC32.mockReset();
@@ -298,17 +294,12 @@ describe('getMultipartUploadHandlers with key', () => {
298294
await multipartUploadJob();
299295

300296
/**
301-
* final crc32 calculation calls calculateContentCRC32 3 times
302-
* 1 time for each of the 2 parts
303-
* 1 time to combine the resulting hash for each of the two parts
304-
*
305-
* uploading each part calls calculateContentCRC32 1 time each
306-
*
307-
* 1 time for optionsHash
308-
*
309-
* these steps results in 6 calls in total
297+
* `calculateContentCRC32` is called 4 times with Full-body checksum:
298+
* * 1 time when calculating final crc32 for the whole object to be uploaded.
299+
* * 1 time when calculating optionsHash.
300+
* * 1 time each when uploading part calls, 2 calls in total.
310301
*/
311-
expect(calculateContentCRC32).toHaveBeenCalledTimes(6);
302+
expect(calculateContentCRC32).toHaveBeenCalledTimes(4);
312303
expect(calculateContentMd5).not.toHaveBeenCalled();
313304
expect(mockUploadPart).toHaveBeenCalledTimes(2);
314305
expect(mockUploadPart).toHaveBeenCalledWith(
@@ -389,7 +380,7 @@ describe('getMultipartUploadHandlers with key', () => {
389380
file.size,
390381
);
391382
await multipartUploadJob();
392-
expect(file.slice).toHaveBeenCalledTimes(10_000 * 2); // S3 limit of parts count double for crc32 calculations
383+
expect(file.slice).toHaveBeenCalledTimes(10_000);
393384
expect(mockCreateMultipartUpload).toHaveBeenCalledTimes(1);
394385
expect(mockUploadPart).toHaveBeenCalledTimes(10_000);
395386
expect(mockCompleteMultipartUpload).toHaveBeenCalledTimes(1);
@@ -1112,17 +1103,12 @@ describe('getMultipartUploadHandlers with path', () => {
11121103
await multipartUploadJob();
11131104

11141105
/**
1115-
* final crc32 calculation calls calculateContentCRC32 3 times
1116-
* 1 time for each of the 2 parts
1117-
* 1 time to combine the resulting hash for each of the two parts
1118-
*
1119-
* uploading each part calls calculateContentCRC32 1 time each
1120-
*
1121-
* 1 time for optionsHash
1122-
*
1123-
* these steps results in 6 calls in total
1106+
* `calculateContentCRC32` is called 4 times with Full-body checksum:
1107+
* * 1 time when calculating final crc32 for the whole object to be uploaded.
1108+
* * 1 time when calculating optionsHash.
1109+
* * 1 time each when uploading part calls, 2 calls in total.
11241110
*/
1125-
expect(calculateContentCRC32).toHaveBeenCalledTimes(6);
1111+
expect(calculateContentCRC32).toHaveBeenCalledTimes(4);
11261112
expect(calculateContentMd5).not.toHaveBeenCalled();
11271113
expect(mockUploadPart).toHaveBeenCalledTimes(2);
11281114
expect(mockUploadPart).toHaveBeenCalledWith(
@@ -1203,7 +1189,7 @@ describe('getMultipartUploadHandlers with path', () => {
12031189
file.size,
12041190
);
12051191
await multipartUploadJob();
1206-
expect(file.slice).toHaveBeenCalledTimes(10_000 * 2); // S3 limit of parts count double for crc32 calculations
1192+
expect(file.slice).toHaveBeenCalledTimes(10_000);
12071193
expect(mockCreateMultipartUpload).toHaveBeenCalledTimes(1);
12081194
expect(mockUploadPart).toHaveBeenCalledTimes(10_000);
12091195
expect(mockCompleteMultipartUpload).toHaveBeenCalledTimes(1);
Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,82 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import {
5-
TextDecoder as TextDecoderPolyfill,
6-
TextEncoder as TextEncoderPolyfill,
7-
} from 'node:util';
4+
import { TextEncoder as TextEncoderPolyfill } from 'node:util';
85

96
import { calculateContentCRC32 } from '../../../../src/providers/s3/utils/crc32';
107

118
global.TextEncoder = TextEncoderPolyfill as any;
12-
global.TextDecoder = TextDecoderPolyfill as any;
139

1410
const MB = 1024 * 1024;
1511
const getBlob = (size: number) => new Blob(['1'.repeat(size)]);
1612
const encoder = new TextEncoder();
17-
const decoder = new TextDecoder();
1813

1914
describe('calculate crc32', () => {
2015
describe.each([
2116
{
2217
type: 'file',
2318
size: '4B',
2419
data: new File(['data'], 'someName'),
25-
expected: {
26-
checksum: 'rfPzYw==',
27-
checksumArrayBuffer: new Uint8Array([173, 243, 243, 99]).buffer,
28-
seed: 2918445923,
29-
},
20+
expected: 'rfPzYw==',
3021
},
3122
{
3223
type: 'blob',
3324
size: '4B',
3425
data: new Blob(['data']),
35-
expected: {
36-
checksum: 'rfPzYw==',
37-
checksumArrayBuffer: new Uint8Array([173, 243, 243, 99]).buffer,
38-
seed: 2918445923,
39-
},
26+
expected: 'rfPzYw==',
4027
},
4128
{
4229
type: 'string',
4330
size: '4B',
4431
data: 'data',
45-
expected: {
46-
checksum: 'rfPzYw==',
47-
checksumArrayBuffer: new Uint8Array([173, 243, 243, 99]).buffer,
48-
seed: 2918445923,
49-
},
32+
expected: 'rfPzYw==',
5033
},
5134
{
5235
type: 'arrayBuffer',
5336
size: '4B',
5437
data: encoder.encode('data').buffer,
55-
expected: {
56-
checksum: 'rfPzYw==',
57-
checksumArrayBuffer: new Uint8Array([173, 243, 243, 99]).buffer,
58-
seed: 2918445923,
59-
},
38+
expected: 'rfPzYw==',
6039
},
6140
{
6241
type: 'arrayBufferView',
6342
size: '4B',
6443
data: new DataView(encoder.encode('1234 data 5678').buffer, 5, 4),
65-
expected: {
66-
checksum: 'rfPzYw==',
67-
checksumArrayBuffer: new Uint8Array([173, 243, 243, 99]).buffer,
68-
seed: 2918445923,
69-
},
44+
expected: 'rfPzYw==',
7045
},
7146
{
7247
type: 'file',
7348
size: '8MB',
7449
data: new File([getBlob(8 * MB)], 'someName'),
75-
expected: {
76-
checksum: '/YBlgg==',
77-
checksumArrayBuffer: new Uint8Array([253, 128, 101, 130]).buffer,
78-
seed: 4253050242,
79-
},
50+
expected: '/YBlgg==',
8051
},
8152
{
8253
type: 'blob',
8354
size: '8MB',
8455
data: getBlob(8 * MB),
85-
expected: {
86-
checksum: '/YBlgg==',
87-
checksumArrayBuffer: new Uint8Array([253, 128, 101, 130]).buffer,
88-
seed: 4253050242,
89-
},
56+
expected: '/YBlgg==',
9057
},
9158
{
9259
type: 'string',
9360
size: '8MB',
9461
data: '1'.repeat(8 * MB),
95-
expected: {
96-
checksum: '/YBlgg==',
97-
checksumArrayBuffer: new Uint8Array([253, 128, 101, 130]).buffer,
98-
seed: 4253050242,
99-
},
62+
expected: '/YBlgg==',
10063
},
10164
{
10265
type: 'arrayBuffer',
10366
size: '8MB',
10467
data: encoder.encode('1'.repeat(8 * MB)).buffer,
105-
expected: {
106-
checksum: '/YBlgg==',
107-
checksumArrayBuffer: new Uint8Array([253, 128, 101, 130]).buffer,
108-
seed: 4253050242,
109-
},
68+
expected: '/YBlgg==',
11069
},
11170
{
11271
type: 'arrayBufferView',
11372
size: '8MB',
11473
data: encoder.encode('1'.repeat(8 * MB)),
115-
expected: {
116-
checksum: '/YBlgg==',
117-
checksumArrayBuffer: new Uint8Array([253, 128, 101, 130]).buffer,
118-
seed: 4253050242,
119-
},
74+
expected: '/YBlgg==',
12075
},
12176
])('output for data type of $type with size $size', ({ data, expected }) => {
12277
it('should match expected checksum results', async () => {
123-
const result = (await calculateContentCRC32(data))!;
124-
expect(result.checksum).toEqual(expected.checksum);
125-
expect(result.seed).toEqual(expected.seed);
126-
expect(decoder.decode(result.checksumArrayBuffer)).toEqual(
127-
decoder.decode(expected.checksumArrayBuffer),
128-
);
78+
const result = await calculateContentCRC32(data);
79+
expect(result).toEqual(expected);
12980
});
13081
});
13182
});

packages/storage/__tests__/providers/s3/utils/getCombinedCrc32.native.test.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)