UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

42 lines (40 loc) 1.42 kB
'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"); const utils_1 = require("./client/utils"); const calculateContentMd5 = async (content) => { const hasher = new md5_js_1.Md5(); if (typeof content === 'string') { hasher.update(content); } else if (ArrayBuffer.isView(content) || content instanceof ArrayBuffer) { const blob = new Blob([content]); const buffer = await readFile(blob); hasher.update(buffer); } else { const buffer = await readFile(content); hasher.update(buffer); } const digest = await hasher.digest(); return (0, utils_1.toBase64)(digest); }; exports.calculateContentMd5 = calculateContentMd5; const readFile = (file) => { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onloadend = () => { if (reader.result) { resolve(reader.result); } reader.onabort = () => reject(new Error('Read aborted')); reader.onerror = () => reject(reader.error); }; if (file !== undefined) reader.readAsArrayBuffer(file); }); }; //# sourceMappingURL=md5.native.js.map