UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

1 lines 2.62 kB
{"version":3,"file":"getCombinedCrc32.native.mjs","sources":["../../../../../src/providers/s3/utils/getCombinedCrc32.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getDataChunker } from '../apis/internal/uploadData/multipart/getDataChunker';\nimport { calculateContentCRC32 } from './crc32';\n/**\n * Calculates a combined CRC32 checksum for the given data.\n *\n * This function chunks the input data, calculates CRC32 for each chunk,\n * and then combines these checksums into a single value.\n *\n * @async\n * @param {StorageUploadDataPayload} data - The data to calculate the checksum for.\n * @param {number | undefined} size - The size of each chunk. If undefined, a default chunk size will be used.\n * @returns {Promise<string>} A promise that resolves to a string containing the combined CRC32 checksum\n * and the number of chunks, separated by a hyphen.\n */\nexport const getCombinedCrc32 = async (data, size) => {\n const crc32List = [];\n const dataChunker = getDataChunker(data, size);\n let totalLength = 0;\n for (const { data: checkData } of dataChunker) {\n const checksum = new Uint8Array((await calculateContentCRC32(checkData)).checksumArrayBuffer);\n totalLength += checksum.length;\n crc32List.push(checksum);\n }\n // Combine all Uint8Arrays into a single Uint8Array\n const combinedArray = new Uint8Array(totalLength);\n let offset = 0;\n for (const crc32Hash of crc32List) {\n combinedArray.set(crc32Hash, offset);\n offset += crc32Hash.length;\n }\n return `${(await calculateContentCRC32(combinedArray.buffer)).checksum}-${crc32List.length}`;\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,gBAAgB,GAAG,OAAO,IAAI,EAAE,IAAI,KAAK;AACtD,IAAI,MAAM,SAAS,GAAG,EAAE;AACxB,IAAI,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC;AAClD,IAAI,IAAI,WAAW,GAAG,CAAC;AACvB,IAAI,KAAK,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,WAAW,EAAE;AACnD,QAAQ,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,CAAC,MAAM,qBAAqB,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC;AACrG,QAAQ,WAAW,IAAI,QAAQ,CAAC,MAAM;AACtC,QAAQ,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;AAChC;AACA;AACA,IAAI,MAAM,aAAa,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC;AACrD,IAAI,IAAI,MAAM,GAAG,CAAC;AAClB,IAAI,KAAK,MAAM,SAAS,IAAI,SAAS,EAAE;AACvC,QAAQ,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC;AAC5C,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAClC;AACA,IAAI,OAAO,CAAC,EAAE,CAAC,MAAM,qBAAqB,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;AAChG;;;;"}