1 | {"version":3,"file":"md5.native.mjs","sources":["../../../../../src/providers/s3/utils/md5.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Buffer } from 'buffer';\nimport { Md5 } from '@smithy/md5-js';\nimport { toBase64 } from './client/utils';\n// The FileReader in React Native 0.71 did not support `readAsArrayBuffer`. This native implementation accomodates this\n// by attempting to use `readAsArrayBuffer` and changing the file reading strategy if it throws an error.\n// TODO: This file should be removable when we drop support for React Native 0.71\nexport const calculateContentMd5 = async (content) => {\n const hasher = new Md5();\n const buffer = content instanceof Blob ? await readFile(content) : content;\n hasher.update(buffer);\n const digest = await hasher.digest();\n return toBase64(digest);\n};\nconst readFile = (file) => new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => {\n resolve(reader.result);\n };\n reader.onabort = () => {\n reject(new Error('Read aborted'));\n };\n reader.onerror = () => {\n reject(reader.error);\n };\n try {\n reader.readAsArrayBuffer(file);\n }\n catch (e) {\n reader.onload = () => {\n // reference: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL\n // response from readAsDataURL is always prepended with \"data:*/*;base64,\"\n const [, base64Data] = reader.result.split(',');\n const arrayBuffer = Buffer.from(base64Data, 'base64');\n resolve(arrayBuffer);\n };\n reader.readAsDataURL(file);\n }\n});\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACY,MAAC,mBAAmB,GAAG,OAAO,OAAO,KAAK;AACtD,IAAI,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;AAC7B,IAAI,MAAM,MAAM,GAAG,OAAO,YAAY,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAC/E,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1B,IAAI,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;AACzC,IAAI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