├── docs ├── .nojekyll ├── assets │ ├── images │ │ ├── icons.png │ │ ├── icons@2x.png │ │ ├── widgets.png │ │ └── widgets@2x.png │ ├── js │ │ └── search.js │ └── css │ │ └── main.css.map ├── globals.html ├── modules │ ├── _manageddownloaderstream_.html │ └── _manageddownloader_.html ├── interfaces │ ├── _manageddownloader_.manageddownloaderoptions.html │ └── _manageddownloader_.getobjectstreaminput.html ├── index.html └── classes │ └── _manageddownloader_.manageddownloader.html ├── src ├── index.ts ├── ManagedDownloaderStream.ts ├── getRangeOfPart.ts ├── getInformationFromRange.ts ├── ManagedDownloader.ts └── test │ ├── integration │ └── ManagedDownloader.integ.spec.ts │ └── unit │ └── ManagedDownloader.spec.ts ├── .gitignore ├── NOTICE ├── .github └── PULL_REQUEST_TEMPLATE.md ├── .npmignore ├── tsconfig.test.json ├── tsconfig.json ├── CODE_OF_CONDUCT.md ├── package.json ├── CONTRIBUTING.md ├── README.md └── LICENSE /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ManagedDownloader'; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | node_modules 3 | package-lock.json 4 | coverage/* 5 | .DS_Store -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | AWS SDK Js S3 Managed Download 2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. -------------------------------------------------------------------------------- /docs/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/s3-managed-download-js/HEAD/docs/assets/images/icons.png -------------------------------------------------------------------------------- /docs/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/s3-managed-download-js/HEAD/docs/assets/images/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/s3-managed-download-js/HEAD/docs/assets/images/widgets.png -------------------------------------------------------------------------------- /docs/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/s3-managed-download-js/HEAD/docs/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | coverage/* 4 | .DS_Store 5 | CODE_OF_CONDUCT.md 6 | CONTRIBUTING.md 7 | tsconfig.* 8 | src/* 9 | docs/* 10 | build/*.spec 11 | .github/* 12 | LICENSE 13 | NOTICE 14 | .gitignore 15 | .npmignore -------------------------------------------------------------------------------- /tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "sourceMap": false, 5 | "inlineSourceMap": true, 6 | "inlineSources": true, 7 | "rootDir": "./src", 8 | "outDir": "./build" 9 | } 10 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "commonjs", 5 | "declaration": true, 6 | "sourceMap": true, 7 | "strict": true, 8 | "lib": [ 9 | "es2015" 10 | ], 11 | "rootDir": "./src", 12 | "outDir": "./build", 13 | } 14 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /src/ManagedDownloaderStream.ts: -------------------------------------------------------------------------------- 1 | import { PassThrough } from 'stream'; 2 | 3 | /** 4 | * ManagedDownloaderStream is a PassThrough 5 | * stream to pass data from S3 to a client 6 | * and contain useful headers. 7 | */ 8 | export class ManagedDownloaderStream extends PassThrough { 9 | /** 10 | * @param mimeType MIME type describing format of the data. 11 | * @param contentLength length of the body in bytes. 12 | */ 13 | mimeType:string|undefined; 14 | contentLength:number|undefined; 15 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@aws/s3-managed-downloader", 3 | "version": "0.9.0", 4 | "description": "Managed Downloader for S3", 5 | "main": "./build/index.js", 6 | "scripts": { 7 | "pretest": "tsc -p tsconfig.test.json", 8 | "test": "jest 'test/unit/*' --coverage", 9 | "integrationtest": "tsc -p tsconfig.test.json && jest test/integration/*", 10 | "documentation": "typedoc --readme README.md --exclude '**/*.spec.ts, **/index.ts, **/getRangeOfPart.ts, **/getInformationFromRange.ts' --out docs --excludeExternals && touch ./docs/.nojekyll", 11 | "build": "tsc -p tsconfig.json", 12 | "prepublishOnly": "tsc -p tsconfig.json" 13 | }, 14 | "dependencies": { 15 | "aws-sdk": "^2.290.0" 16 | }, 17 | "devDependencies": { 18 | "@types/jest": "^20.0.0", 19 | "@types/node": "^10.3.4", 20 | "jest": "^20.0.0", 21 | "typedoc": "^0.11.1", 22 | "typescript": "^3.0.1" 23 | }, 24 | "jest": { 25 | "testEnvironment": "node" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/getRangeOfPart.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get the range of bytes as a string 3 | * based on the starting part, max 4 | * part size, and contentLength. 5 | * @param partNum the part number. 6 | * @param totalObjectLength length of the file. 7 | * @param maxPartSize the size of the part. 8 | * @param byteOffset offset the start and end 9 | * by this number. This is necessary for accounting 10 | * for the offset when the client provides a range. 11 | * @return string range in proper format. 12 | */ 13 | export function getRangeOfPart( 14 | partNum:number, 15 | totalObjectLength:number, 16 | maxPartSize:number, 17 | byteOffset:number = 0 18 | ):string { 19 | let range:string = ''; 20 | const startByte:number = (partNum * maxPartSize) + byteOffset; 21 | const endByte:number = Math.min(totalObjectLength, (partNum + 1) 22 | * maxPartSize) + byteOffset; 23 | // range is inclusive start and end byte so subtract 1 24 | range = 'bytes=' + startByte + '-' + (endByte - 1); 25 | return range; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/getInformationFromRange.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Information on the start byte, end byte, and length 3 | * of a range of bytes. 4 | */ 5 | export interface RangeInfo { 6 | /** 7 | * @param startByte the starting byte of the range. 8 | * @param endByte the last byte of the range. 9 | * @param length the length of the range. 10 | */ 11 | startByte:number, 12 | endByte:number, 13 | length:number 14 | } 15 | 16 | /** 17 | * Find important information from the user provided range. 18 | * @param range client provided string range in format 19 | * bytes=x-y. 20 | * @return RangeInfo the start byte, end byte, and length 21 | * of the part. 22 | */ 23 | export function getInformationFromRange(range:string):RangeInfo { 24 | const regExp:RegExp = /^bytes=([0-9]+)-([0-9]+)$/; 25 | const bytes:RegExpExecArray|null = regExp.exec(range); 26 | if (bytes == null) { 27 | throw new Error("Invalid Range provided by client"); 28 | } 29 | return { 30 | startByte:parseInt(bytes[1]), 31 | endByte:parseInt(bytes[2]), 32 | length:parseInt(bytes[2]) - parseInt(bytes[1]) 33 | } 34 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/awslabs/aws-sdk-js-s3-transfer-manager/issues), or [recently closed](https://github.com/awslabs/aws-sdk-js-s3-transfer-manager/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-sdk-js-s3-transfer-manager/labels/help%20wanted) issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](https://github.com/awslabs/aws-sdk-js-s3-transfer-manager/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS SDK JavaScript S3 Managed Download 2 | 3 | The JavaScript SDK Managed Download can be used for custom S3 downloads. The client can configure options for the Managed Download such as chunk size and number of concurrent transfers. 4 | 5 | ## Installing 6 | 7 | ### In Node.js 8 | 9 | This package only works in Node.js versions 6+ currently. Use the npm package manager for Node.js to install the Managed Download package. Type the following command in a terminal window. 10 | 11 | npm install @aws/s3-managed-download 12 | 13 | ## Documentation 14 | 15 | You can find the full documentation for the Managed Download package [here](https://awslabs.github.io/s3-managed-download-js/). 16 | 17 | ## Configuration 18 | 19 | You can customize the part size and number of concurrent downloads for the Managed Download by setting the maxPartSize and maxConcurrency options. The maxPartSize option controls the size in bytes of each part of the transfer. The maxConcurrency option specifies the number of parts that will be downloaded in parallel and the maximum number of parts that will be buffered in memory at any time. 20 | 21 | ### Import the Managed Download package 22 | 23 | You will need an S3 client in order to create a managed download, so import the aws-sdk along with the managed download package. 24 | 25 | #### JavaScript 26 | 27 | const S3 = require('aws-sdk/clients/s3'); 28 | const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader; 29 | 30 | #### TypeScript 31 | 32 | import * as S3 from 'aws-sdk/clients/s3'; 33 | import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download'; 34 | 35 | ### Create a Managed Download with the default part size and concurrency 36 | 37 | Create an AWS S3 client and pass the client into the Managed Download constructor to create a Managed Download with a part size of 5MB and concurrency of 1. 38 | 39 | #### JavaScript 40 | 41 | const s3 = new S3(); 42 | const managedDownloader = new ManagedDownloader(s3); 43 | 44 | #### TypeScript 45 | 46 | const s3:S3 = new S3(); 47 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3); 48 | 49 | ### Create a Managed Download with custom part size and concurrency 50 | 51 | Create an AWS S3 client and Managed Download options. Pass the client and the options into the Managed Download constructor to create a Managed Download with a custom part size of 10MB and concurrency of 5. 52 | 53 | #### JavaScript 54 | 55 | const s3 = new S3(); 56 | const options = { 57 | maxPartSize: 10 * 1024 * 1024, 58 | maxConcurrency: 5 59 | }; 60 | const managedDownloader = new ManagedDownloader(s3, options); 61 | 62 | #### TypeScript 63 | 64 | const s3:S3 = new S3(); 65 | const options:ManagedDownloaderOptons = { 66 | maxPartSize: 10 * 1024 * 1024, 67 | maxConcurrency: 5 68 | }; 69 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3, options); 70 | 71 | ## Examples 72 | 73 | Currently, the Managed Download only contains a streaming download operation which can work for an entire file or a specific range or part of a file. Here are some examples on 74 | how to use the Managed Download's getObjectStream download operation. 75 | 76 | 77 | 78 | ### 1. Use the Managed Download object to create a download stream for a file on S3 79 | 80 | Get the file 'example-key' from the bucket 'example-bucket' and use the getObjectStream method to create a local file at 'example-file-path'. 81 | 82 | #### JavaScript 83 | 84 | const S3 = require('aws-sdk/clients/s3'); 85 | const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader; 86 | const fs = require('fs'); 87 | 88 | const s3 = new S3(); 89 | const managedDownloader = new ManagedDownloader(s3); 90 | 91 | const params = { 92 | Bucket: 'example-bucket', 93 | Key: 'example-key' 94 | }; 95 | // create a write stream for a file 96 | const writeStream = fs.createWriteStream('example-file-path'); 97 | 98 | managedDownloader.getObjectStream(params) 99 | .then((stream) => { 100 | stream.pipe(writeStream); 101 | }, (err) => { 102 | writeStream.end(); 103 | console.error(err); 104 | }); 105 | 106 | #### TypeScript 107 | 108 | import * as S3 from 'aws-sdk/clients/s3'; 109 | import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download'; 110 | import * as fs from 'fs'; 111 | 112 | const s3:S3 = new S3(); 113 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3); 114 | 115 | const params:GetObjectStreamInput = { 116 | Bucket: 'example-bucket', 117 | Key: 'example-key' 118 | }; 119 | // create a write stream for a file 120 | const writeStream:fs.WriteStream = fs.createWriteStream('example-file-path'); 121 | 122 | managedDownloader.getObjectStream(params) 123 | .then((stream) => { 124 | stream.pipe(writeStream); 125 | }, (err) => { 126 | writeStream.end(); 127 | console.error(err); 128 | }); 129 | 130 | ### 2. Use the Managed Download object to create a download stream for a range of bytes of a file on S3 131 | 132 | Get the file 'example-key' from the bucket 'example-bucket' and use the getObjectStream method to write to bytes 100-150 of a local file at 'example-file-path'. 133 | 134 | #### JavaScript 135 | 136 | const S3 = require('aws-sdk/clients/s3'); 137 | const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader; 138 | const fs = require('fs'); 139 | 140 | const s3 = new S3(); 141 | const managedDownloader = new ManagedDownloader(s3); 142 | 143 | const params = { 144 | Bucket: 'example-bucket', 145 | Key: 'example-key', 146 | Range: '100-150' 147 | }; 148 | // create a write stream for a file starting at byte 100 149 | const writeStream = fs.createWriteStream('example-file-path', {start:100}); 150 | 151 | managedDownloader.getObjectStream(params) 152 | .then((stream) => { 153 | stream.pipe(writeStream); 154 | }, (err) => { 155 | writeStream.end(); 156 | console.error(err); 157 | }); 158 | 159 | #### TypeScript 160 | 161 | import * as S3 from 'aws-sdk/clients/s3'; 162 | import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download'; 163 | import * as fs from 'fs'; 164 | 165 | const s3:S3 = new S3(); 166 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3); 167 | 168 | const params:GetObjectStreamInput = { 169 | Bucket: 'example-bucket', 170 | Key: 'example-key', 171 | Range: '100-150' 172 | }; 173 | // create a write stream for a file starting at byte 100 174 | const writeStream:fs.WriteStream = fs.createWriteStream('example-file-path', {start:100}); 175 | 176 | managedDownloader.getObjectStream(params) 177 | .then((stream) => { 178 | stream.pipe(writeStream); 179 | }, (err) => { 180 | writeStream.end(); 181 | console.error(err); 182 | }); 183 | 184 | ## Opening Issues 185 | 186 | If you find any bugs or want to request a new feature, please first check the existing issues. If there is not already an issue, then open a new issue. If the issue is regarding a bug, please include the stack trace and a method to recreate it. 187 | 188 | ## License 189 | 190 | This library is licensed under the Apache 2.0 License. 191 | -------------------------------------------------------------------------------- /docs/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |Generated using TypeDoc
161 |Generated using TypeDoc
166 |Generated using TypeDoc
179 |Generated using TypeDoc
237 |Parameter type for the getObjectStream function.
74 |Generated using TypeDoc
274 |The JavaScript SDK Managed Download can be used for custom S3 downloads. The client can configure options for the Managed Download such as chunk size and number of concurrent transfers.
67 |This package only works in Node.js versions 6+ currently. Use the npm package manager for Node.js to install the Managed Download package. Type the following command in a terminal window.
70 | npm install @aws/s3-managed-download
71 | You can find the full documentation for the Managed Download package here.
73 |You can customize the part size and number of concurrent downloads for the Managed Download by setting the maxPartSize and maxConcurrency options. The maxPartSize option controls the size in bytes of each part of the transfer. The maxConcurrency option specifies the number of parts that will be downloaded in parallel and the maximum number of parts that will be buffered in memory at any time.
75 |You will need an S3 client in order to create a managed download, so import the aws-sdk along with the managed download package.
77 | const S3 = require('aws-sdk/clients/s3');
79 | const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader;
80 | import * as S3 from 'aws-sdk/clients/s3';
82 | import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download';
83 | Create an AWS S3 client and pass the client into the Managed Download constructor to create a Managed Download with a part size of 5MB and concurrency of 1.
85 | const s3 = new S3();
87 | const managedDownloader = new ManagedDownloader(s3);
88 | const s3:S3 = new S3();
90 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3);
91 | Create an AWS S3 client and Managed Download options. Pass the client and the options into the Managed Download constructor to create a Managed Download with a custom part size of 10MB and concurrency of 5.
93 | const s3 = new S3();
95 | const options = {
96 | maxPartSize: 10 * 1024 * 1024,
97 | maxConcurrency: 5
98 | };
99 | const managedDownloader = new ManagedDownloader(s3, options);
100 | const s3:S3 = new S3();
102 | const options:ManagedDownloaderOptons = {
103 | maxPartSize: 10 * 1024 * 1024,
104 | maxConcurrency: 5
105 | };
106 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3, options);
107 | Currently, the Managed Download only contains a streaming download operation which can work for an entire file or a specific range or part of a file. Here are some examples on 109 | how to use the Managed Download's getObjectStream download operation.
110 |Get the file 'example-key' from the bucket 'example-bucket' and use the getObjectStream method to create a local file at 'example-file-path'.
112 | const S3 = require('aws-sdk/clients/s3');
114 | const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader;
115 | const fs = require('fs');
116 |
117 | const s3 = new S3();
118 | const managedDownloader = new ManagedDownloader(s3);
119 |
120 | const params = {
121 | Bucket: 'example-bucket',
122 | Key: 'example-key'
123 | };
124 | // create a write stream for a file
125 | const writeStream = fs.createWriteStream('example-file-path');
126 |
127 | managedDownloader.getObjectStream(params)
128 | .then((stream) => {
129 | stream.pipe(writeStream);
130 | }, (err) => {
131 | writeStream.end();
132 | console.error(err);
133 | });
134 | import * as S3 from 'aws-sdk/clients/s3';
136 | import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download';
137 | import * as fs from 'fs';
138 |
139 | const s3:S3 = new S3();
140 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3);
141 |
142 | const params:GetObjectStreamInput = {
143 | Bucket: 'example-bucket',
144 | Key: 'example-key'
145 | };
146 | // create a write stream for a file
147 | const writeStream:fs.WriteStream = fs.createWriteStream('example-file-path');
148 |
149 | managedDownloader.getObjectStream(params)
150 | .then((stream) => {
151 | stream.pipe(writeStream);
152 | }, (err) => {
153 | writeStream.end();
154 | console.error(err);
155 | });
156 | Get the file 'example-key' from the bucket 'example-bucket' and use the getObjectStream method to write to bytes 100-150 of a local file at 'example-file-path'.
158 | const S3 = require('aws-sdk/clients/s3');
160 | const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader;
161 | const fs = require('fs');
162 |
163 | const s3 = new S3();
164 | const managedDownloader = new ManagedDownloader(s3);
165 |
166 | const params = {
167 | Bucket: 'example-bucket',
168 | Key: 'example-key',
169 | Range: '100-150'
170 | };
171 | // create a write stream for a file starting at byte 100
172 | const writeStream = fs.createWriteStream('example-file-path', {start:100});
173 |
174 | managedDownloader.getObjectStream(params)
175 | .then((stream) => {
176 | stream.pipe(writeStream);
177 | }, (err) => {
178 | writeStream.end();
179 | console.error(err);
180 | });
181 | import * as S3 from 'aws-sdk/clients/s3';
183 | import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download';
184 | import * as fs from 'fs';
185 |
186 | const s3:S3 = new S3();
187 | const managedDownloader:ManagedDownloader = new ManagedDownloader(s3);
188 |
189 | const params:GetObjectStreamInput = {
190 | Bucket: 'example-bucket',
191 | Key: 'example-key',
192 | Range: '100-150'
193 | };
194 | // create a write stream for a file starting at byte 100
195 | const writeStream:fs.WriteStream = fs.createWriteStream('example-file-path', {start:100});
196 |
197 | managedDownloader.getObjectStream(params)
198 | .then((stream) => {
199 | stream.pipe(writeStream);
200 | }, (err) => {
201 | writeStream.end();
202 | console.error(err);
203 | });
204 | If you find any bugs or want to request a new feature, please first check the existing issues. If there is not already an issue, then open a new issue. If the issue is regarding a bug, please include the stack trace and a method to recreate it.
206 |This library is licensed under the Apache 2.0 License.
208 |Generated using TypeDoc
292 |The ManagedDownloader class handles custom S3 downloads. 74 | A client can set options for the download such as 75 | the part size and the concurrency.
76 |Create a ManagedDownloader object with an 134 | s3 client and custom options if provided.
135 |an S3 client to make requests.
155 |configuration for the managed download.
163 |an S3 client to make requests.
186 |Download the individual parts of the file 238 | and write them to the stream sequentially. 239 | Download n = this.maxConcurrency parts 240 | in parallel and store parts which 241 | aren't the next part in memory until the 242 | stream is ready to read it.
243 |params object contains the bucket 251 | and key.
252 |the ManagedDownloaderStream stream 258 | transferring the parts of a file.
259 |the length of the file.
265 |if available, the amount to add to start 271 | and end byte when calculating the range.
272 |the part number to start downloading from.
278 |Get a download stream for a file stored in s3. 301 | Download the first part of size [maxPartSize] to get 302 | the content length and set headers for the stream. 303 | If the file length is less than [maxPartSize], or the 304 | client provides a part number, then return the stream. 305 | If not, call downloadByParts to split the rest of the file into 306 | parts of size [maxPartSize] and download [maxConcurrency] parts 307 | in parallel.
308 |an object in the format 321 | { 322 | Bucket:string, 323 | Key:string, 324 | Range(optional):string, 325 | PartNumber(optional):number 326 | }.
327 |ManagedDownloaderStream the PassThrough stream to read 332 | file data from.
333 |wait for a stream to emit a 352 | drain event when it is ready to 353 | receive data again.
354 |the stream 362 | that is being watched for the drain 363 | event.
364 |Generated using TypeDoc
491 |
Custom options for the Managed Download.
74 |