1 | {"version":3,"file":"downloadData.mjs","sources":["../../../../../src/providers/s3/apis/downloadData.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { StorageAction } from '@aws-amplify/core/internals/utils';\nimport { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput';\nimport { createDownloadTask } from '../utils';\nimport { getObject } from '../utils/client';\nimport { getStorageUserAgentValue } from '../utils/userAgent';\nimport { logger } from '../../../utils';\n/**\n * Download S3 object data to memory\n *\n * @param input - The DownloadDataInput object.\n * @returns A cancelable task exposing result promise from `result` property.\n * @throws service: {@link S3Exception} - thrown when checking for existence of the object\n * @throws validation: {@link StorageValidationErrorCode } - Validation errors\n *\n * @example\n * ```ts\n * // Download a file from s3 bucket\n * const { body, eTag } = await downloadData({ key, data: file, options: {\n * onProgress, // Optional progress callback.\n * } }).result;\n * ```\n * @example\n * ```ts\n * // Cancel a task\n * const downloadTask = downloadData({ key, data: file });\n * //...\n * downloadTask.cancel();\n * try {\n * \tawait downloadTask.result;\n * } catch (error) {\n * \tif(isCancelError(error)) {\n * // Handle error thrown by task cancelation.\n * \t}\n * }\n *```\n */\nexport const downloadData = (input) => {\n const abortController = new AbortController();\n const downloadTask = createDownloadTask({\n job: downloadDataJob(input, abortController.signal),\n onCancel: (message) => {\n abortController.abort(message);\n },\n });\n return downloadTask;\n};\nconst downloadDataJob = ({ options: downloadDataOptions, key }, abortSignal) => async () => {\n const { bucket, keyPrefix, s3Config } = await resolveS3ConfigAndInput(Amplify, downloadDataOptions);\n const finalKey = keyPrefix + key;\n logger.debug(`download ${key} from ${finalKey}.`);\n const { Body: body, LastModified: lastModified, ContentLength: size, ETag: eTag, Metadata: metadata, VersionId: versionId, ContentType: contentType, } = await getObject({\n ...s3Config,\n abortSignal,\n onDownloadProgress: downloadDataOptions?.onProgress,\n userAgentValue: getStorageUserAgentValue(StorageAction.DownloadData),\n }, {\n Bucket: bucket,\n Key: finalKey,\n ...(downloadDataOptions?.bytesRange && {\n Range: `bytes=${downloadDataOptions.bytesRange.start}-${downloadDataOptions.bytesRange.end}`,\n }),\n });\n return {\n key,\n body,\n lastModified,\n size,\n contentType,\n eTag,\n metadata,\n versionId,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,CAAC,KAAK,KAAK;AACvC,IAAI,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAClD,IAAI,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAC5C,QAAQ,GAAG,EAAE,eAAe,CAAC,KAAK,EAAE,eAAe,CAAC,MAAM,CAAC;AAC3D,QAAQ,QAAQ,EAAE,CAAC,OAAO,KAAK;AAC/B,YAAY,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3C,SAAS;AACT,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,YAAY,CAAC;AACxB,EAAE;AACF,MAAM,eAAe,GAAG,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,EAAE,WAAW,KAAK,YAAY;AAC5F,IAAI,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACxG,IAAI,MAAM,QAAQ,GAAG,SAAS,GAAG,GAAG,CAAC;AACrC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACtD,IAAI,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE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