UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

21 lines (18 loc) 757 B
import { Md5 } from '@smithy/md5-js'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 /** * Calculate the MD5 checksum of the given content as a base64 string. * Environment-specific dependencies (`readFile`, `toBase64`) are injected * via the {@link FoundationContext} so the foundation layer stays free of * any environment-discriminating logic. */ const calculateContentMd5 = async (ctx, content) => { const hasher = new Md5(); const buffer = content instanceof Blob ? await ctx.readFile(content) : content; hasher.update(buffer); const digest = await hasher.digest(); return ctx.toBase64(digest); }; export { calculateContentMd5 }; //# sourceMappingURL=md5.mjs.map