UNPKG

1.13 kBJavaScriptView Raw
1import { Md5 } from '@smithy/md5-js';
2import '@aws-amplify/core/internals/aws-client-utils';
3import './client/runtime/s3TransferHandler/fetch.mjs';
4import 'fast-xml-parser';
5import './client/runtime/s3TransferHandler/xhr.mjs';
6import { toBase64 } from './client/runtime/base64/index.native.mjs';
7import '@aws-amplify/core/internals/utils';
8
9// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
10// SPDX-License-Identifier: Apache-2.0
11const calculateContentMd5 = async (content) => {
12 const hasher = new Md5();
13 const buffer = content instanceof Blob ? await readFile(content) : content;
14 hasher.update(buffer);
15 const digest = await hasher.digest();
16 return toBase64(digest);
17};
18const readFile = (file) => new Promise((resolve, reject) => {
19 const reader = new FileReader();
20 reader.onload = () => {
21 resolve(reader.result);
22 };
23 reader.onabort = () => {
24 reject(new Error('Read aborted'));
25 };
26 reader.onerror = () => {
27 reject(reader.error);
28 };
29 reader.readAsArrayBuffer(file);
30});
31
32export { calculateContentMd5 };
33//# sourceMappingURL=md5.mjs.map