UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

23 lines (21 loc) 904 B
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateContentMd5 = void 0; const md5_js_1 = require("@smithy/md5-js"); /** * 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_js_1.Md5(); const buffer = content instanceof Blob ? await ctx.readFile(content) : content; hasher.update(buffer); const digest = await hasher.digest(); return ctx.toBase64(digest); }; exports.calculateContentMd5 = calculateContentMd5; //# sourceMappingURL=md5.js.map