Skip to content

Commit 8daad36

Browse files
committed
chore: cr changes for readme and added download() examples
1 parent 21fdc36 commit 8daad36

File tree

1 file changed

+113
-17
lines changed
  • lib/lib-storage/src/s3-transfer-manager

1 file changed

+113
-17
lines changed

lib/lib-storage/src/s3-transfer-manager/README.md

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# @aws-sdk/lib-storage/s3-transfer-manager
22

3+
> 🚧 **Package Currently Under Development**
4+
35
[![NPM version](https://img.shields.io/npm/v/@aws-sdk/lib-storage/latest.svg)](https://www.npmjs.com/package/@aws-sdk/lib-storage)
46
[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/lib-storage.svg)](https://www.npmjs.com/package/@aws-sdk/lib-storage)
57

6-
## Overview
8+
# Overview
79

8-
S3TransferManager is a high level library that helps customers interact with S3
10+
S3TransferManager is a high level library that helps users interact with S3
911
for their most common use cases that involve multiple API operations through SDK JS V3.
1012
S3TransferManager provides the following features:
1113

@@ -19,7 +21,7 @@ S3TransferManager provides the following features:
1921

2022
`npm install @aws-sdk/lib-storage`
2123

22-
## Getting Started
24+
# Getting Started
2325

2426
### Import
2527

@@ -71,19 +73,29 @@ console.log(`Downloaded ${data.byteLength} bytes`);
7173
7274
The S3TransferManager constructor accepts an optional `S3TransferManagerConfig` object with the following optional properties:
7375
74-
| Option | Type | Default | Description |
75-
| ------------------------------- | ------------------------ | ------------------------------------- | ------------------------------------------------- |
76-
| `s3ClientInstance` | `S3Client` | `new S3Client()` with checksum config | S3 client instance for API calls |
77-
| `targetPartSizeBytes` | `number` | `8388608` (8MB) | Target size for each part in multipart operations |
78-
| `multipartUploadThresholdBytes` | `number` | `16777216` (16MB) | File size threshold to trigger multipart upload |
79-
| `checksumValidationEnabled` | `boolean` | `true` | Enable checksum validation for data integrity |
80-
| `checksumAlgorithm` | `ChecksumAlgorithm` | `"CRC32"` | Algorithm used for checksum calculation |
81-
| `multipartDownloadType` | `"PART" \| "RANGE"` | `"PART"` | Strategy for multipart downloads |
82-
| `eventListeners` | `TransferEventListeners` | `{}` | Event listeners for transfer progress |
76+
| Option | Type | Default | Description |
77+
| ------------------------------- | ------------------------ | ----------------- | ------------------------------------------------- |
78+
| `s3ClientInstance` | `S3Client` | `new S3Client()` | S3 client instance for API calls |
79+
| `targetPartSizeBytes` | `number` | `8388608` (8MB) | Target size for each part in multipart operations |
80+
| `multipartUploadThresholdBytes` | `number` | `16777216` (16MB) | File size threshold to trigger multipart upload |
81+
| `checksumValidationEnabled` | `boolean` | `true` | Enable checksum validation for data integrity |
82+
| `checksumAlgorithm` | `ChecksumAlgorithm` | `"CRC32"` | Algorithm used for checksum calculation |
83+
| `multipartDownloadType` | `"PART" \| "RANGE"` | `"PART"` | Strategy for multipart downloads |
84+
| `eventListeners` | `TransferEventListeners` | `{}` | Event listeners for transfer progress |
8385
8486
**Example:**
8587
8688
```js
89+
const myInitiatedHandler = ({ request }) => {
90+
console.log(`Started: ${request.Key}`);
91+
};
92+
93+
const myProgressHandler = ({ snapshot }) => {
94+
const percent = snapshot.totalBytes ? (snapshot.transferredBytes / snapshot.totalBytes) * 100 : 0;
95+
console.log(`Progress: ${percent.toFixed(1)}%`);
96+
};
97+
98+
// Transfer Manager with optional config properties
8799
const tm = new S3TransferManager({
88100
s3ClientInstance: new S3Client({ region: "us-west-2" }),
89101
targetPartSizeBytes: 10 * 1024 * 1024, // 10MB
@@ -98,15 +110,15 @@ const tm = new S3TransferManager({
98110
});
99111
```
100112
101-
## Methods
113+
# Methods
102114
103-
### upload()
115+
## upload()
104116
105117
> 🚧 **Under Development**
106118
>
107119
> Documentation will be available when this feature is implemented.
108120
109-
### download()
121+
## download()
110122
111123
Downloads objects from S3 using multipart download with two modes:
112124
@@ -153,6 +165,60 @@ Both modes validate data integrity:
153165
154166
We do not recommend updating the object you're downloading mid-download as this may throw a [Precondition Failed error](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/http-412-precondition-failed.html).
155167
168+
### Download Examples:
169+
170+
**PART Download:**
171+
172+
```js
173+
// Configure for PART mode
174+
const tm = new S3TransferManager({
175+
s3ClientInstance: s3Client,
176+
multipartDownloadType: "PART",
177+
});
178+
179+
const download = await tm.download({
180+
Bucket: "my-bucket",
181+
Key: "large-file.zip",
182+
});
183+
184+
const data = await download.Body?.transformToByteArray();
185+
```
186+
187+
**RANGE Download:**
188+
189+
```js
190+
// Configure for RANGE mode
191+
const tm = new S3TransferManager({
192+
s3ClientInstance: s3Client,
193+
multipartDownloadType: "RANGE",
194+
});
195+
196+
const download = await tm.download({
197+
Bucket: "my-bucket",
198+
Key: "document.pdf",
199+
});
200+
201+
const data = await download.Body?.transformToByteArray();
202+
```
203+
204+
**RANGE Download with Specific Range:**
205+
206+
```js
207+
const tm = new S3TransferManager({
208+
s3ClientInstance: s3Client,
209+
multipartDownloadType: "RANGE",
210+
});
211+
212+
// Download first 1MB only
213+
const download = await tm.download({
214+
Bucket: "my-bucket",
215+
Key: "video.mp4",
216+
Range: "bytes=0-1048575",
217+
});
218+
219+
const data = await download.Body?.transformToByteArray();
220+
```
221+
156222
#### uploadAll()
157223
158224
> 🚧 **Under Development**
@@ -265,9 +331,9 @@ tm.addEventListener(
265331
266332
### removeEventListener()
267333
268-
Removes a previously registered event listener from the specified event type. You must pass the exact same function reference that was used when adding the listener.
334+
Removes a previously registered event listener from the specified event type.
269335
270-
**Important:** If you plan to remove event listeners during transfer lifecycle, define your callback as a named function or variable - you cannot remove anonymous functions.
336+
**Important:** If you plan to remove event listeners during transfer lifecycle, define your callback as a named function or variable as you cannot remove anonymous functions.
271337
272338
**Parameters:**
273339
@@ -367,6 +433,27 @@ try {
367433
368434
Event listeners can be configured at two levels: **client-level** (applies to all transfers) and **request-level** (applies to specific transfers). (see [Event Handling](#event-handling))
369435
436+
In the following code we will define basic callback functions that will be used in the proceeding examples:
437+
438+
```js
439+
const downloadingKey = ({ request }) => {
440+
console.log(`Started: ${request.Key}`);
441+
};
442+
443+
const progressBar = ({ snapshot }) => {
444+
const percent = snapshot.totalBytes ? (snapshot.transferredBytes / snapshot.totalBytes) * 100 : 0;
445+
console.log(`Progress: ${percent.toFixed(1)}%`);
446+
};
447+
448+
const transferComplete = ({ request, snapshot }) => {
449+
console.log(`Completed: ${request.Key} (${snapshot.transferredBytes} bytes)`);
450+
};
451+
452+
const transferFailed = ({ request }) => {
453+
console.log(`Failed: ${request.Key}`);
454+
};
455+
```
456+
370457
**Client-Level Event Listeners:**
371458
372459
You can configure the event listeners when creating your Transfer Manager instance. These listeners apply to all transfers made with this instance.
@@ -430,6 +517,15 @@ const download = await tm.download(
430517
Because request-level listeners are added to client-level listeners (not replaced), it allows for global logging plus request-specific handling.
431518
432519
```js
520+
const globalErrorHandler = ({ request }) => {
521+
console.error(`Global error: ${request.Key} failed`);
522+
};
523+
524+
const videoProgressBar = ({ snapshot }) => {
525+
const percent = snapshot.totalBytes ? (snapshot.transferredBytes / snapshot.totalBytes) * 100 : 0;
526+
console.log(`Video download: ${percent.toFixed(1)}%`);
527+
};
528+
433529
// Client-level: global logging
434530
const tm = new S3TransferManager({
435531
s3ClientInstance: s3Client,

0 commit comments

Comments
 (0)