1 | import { Amplify } from '@aws-amplify/core';
|
2 | import { StorageAction } from '@aws-amplify/core/internals/utils';
|
3 | import { resolveS3ConfigAndInput } from '../utils/resolveS3ConfigAndInput.mjs';
|
4 | import '@smithy/md5-js';
|
5 | import '@aws-amplify/core/internals/aws-client-utils';
|
6 | import '../utils/client/runtime/s3TransferHandler/fetch.mjs';
|
7 | import 'fast-xml-parser';
|
8 | import '../utils/client/runtime/s3TransferHandler/xhr.mjs';
|
9 | import 'buffer';
|
10 | import { createDownloadTask } from '../utils/transferTask.mjs';
|
11 | import '../utils/client/base.mjs';
|
12 | import { getObject } from '../utils/client/getObject.mjs';
|
13 | import '../utils/client/listObjectsV2.mjs';
|
14 | import '../utils/client/putObject.mjs';
|
15 | import '../utils/client/createMultipartUpload.mjs';
|
16 | import '../utils/client/uploadPart.mjs';
|
17 | import '../utils/client/completeMultipartUpload.mjs';
|
18 | import '../utils/client/listParts.mjs';
|
19 | import '../utils/client/abortMultipartUpload.mjs';
|
20 | import '../utils/client/copyObject.mjs';
|
21 | import '../utils/client/headObject.mjs';
|
22 | import '../utils/client/deleteObject.mjs';
|
23 | import { getStorageUserAgentValue } from '../utils/userAgent.mjs';
|
24 | import '../../../errors/types/validation.mjs';
|
25 | import { logger } from '../../../utils/logger.mjs';
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | const downloadData = (input) => {
|
60 | const abortController = new AbortController();
|
61 | const downloadTask = createDownloadTask({
|
62 | job: downloadDataJob(input, abortController.signal),
|
63 | onCancel: (message) => {
|
64 | abortController.abort(message);
|
65 | },
|
66 | });
|
67 | return downloadTask;
|
68 | };
|
69 | const downloadDataJob = ({ options: downloadDataOptions, key }, abortSignal) => async () => {
|
70 | const { bucket, keyPrefix, s3Config } = await resolveS3ConfigAndInput(Amplify, downloadDataOptions);
|
71 | const finalKey = keyPrefix + key;
|
72 | logger.debug(`download ${key} from ${finalKey}.`);
|
73 | const { Body: body, LastModified: lastModified, ContentLength: size, ETag: eTag, Metadata: metadata, VersionId: versionId, ContentType: contentType, } = await getObject({
|
74 | ...s3Config,
|
75 | abortSignal,
|
76 | onDownloadProgress: downloadDataOptions?.onProgress,
|
77 | userAgentValue: getStorageUserAgentValue(StorageAction.DownloadData),
|
78 | }, {
|
79 | Bucket: bucket,
|
80 | Key: finalKey,
|
81 | ...(downloadDataOptions?.bytesRange && {
|
82 | Range: `bytes=${downloadDataOptions.bytesRange.start}-${downloadDataOptions.bytesRange.end}`,
|
83 | }),
|
84 | });
|
85 | return {
|
86 | key,
|
87 | body,
|
88 | lastModified,
|
89 | size,
|
90 | contentType,
|
91 | eTag,
|
92 | metadata,
|
93 | versionId,
|
94 | };
|
95 | };
|
96 |
|
97 | export { downloadData };
|
98 |
|