@aws/s3-managed-downloader

中文文档
0.9.0发布于 2018/09/12CommonJS近 30 天下载 3891

Managed Downloader for S3

原始使用文档
文档目录12 节
  1. Installing
  2. In Node.js
  3. Documentation
  4. Configuration
  5. Import the Managed Download package
  6. Create a Managed Download with the default part size and co…
  7. Create a Managed Download with custom part size and concurr…
  8. Examples
  9. 1. Use the Managed Download object to create a download str…
  10. 2. Use the Managed Download object to create a download str…
  11. Opening Issues
  12. License

AWS SDK JavaScript S3 Managed Download

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.

Installing

In Node.js

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.

    npm install @aws/s3-managed-download

Documentation

You can find the full documentation for the Managed Download package here.

Configuration

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.

Import the Managed Download package

You will need an S3 client in order to create a managed download, so import the aws-sdk along with the managed download package.

JavaScript

    const S3 = require('aws-sdk/clients/s3');
    const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader;

TypeScript

    import * as S3 from 'aws-sdk/clients/s3';
    import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download';

Create a Managed Download with the default part size and concurrency

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.

JavaScript

    const s3 = new S3();
    const managedDownloader = new ManagedDownloader(s3);

TypeScript

    const s3:S3 = new S3();
    const managedDownloader:ManagedDownloader = new ManagedDownloader(s3);

Create a Managed Download with custom part size and concurrency

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.

JavaScript

    const s3 = new S3();
    const options = {
        maxPartSize: 10 * 1024 * 1024,
        maxConcurrency: 5
    };
    const managedDownloader = new ManagedDownloader(s3, options);

TypeScript

    const s3:S3 = new S3();
    const options:ManagedDownloaderOptons = {
        maxPartSize: 10 * 1024 * 1024,
        maxConcurrency: 5
    };
    const managedDownloader:ManagedDownloader = new ManagedDownloader(s3, options);

Examples

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 how to use the Managed Download's getObjectStream download operation.

1. Use the Managed Download object to create a download stream for a file on S3

Get the file 'example-key' from the bucket 'example-bucket' and use the getObjectStream method to create a local file at 'example-file-path'.

JavaScript

    const S3 = require('aws-sdk/clients/s3');
    const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader;
    const fs = require('fs');

    const s3 = new S3();
    const managedDownloader = new ManagedDownloader(s3);

    const params = {
        Bucket: 'example-bucket',
        Key: 'example-key'
    };
    // create a write stream for a file
    const writeStream = fs.createWriteStream('example-file-path');
    
    managedDownloader.getObjectStream(params)
    .then((stream) => {
        stream.pipe(writeStream);
    }, (err) => {
        writeStream.end();
        console.error(err);
    });

TypeScript

    import * as S3 from 'aws-sdk/clients/s3';
    import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download';
    import * as fs from 'fs';

    const s3:S3 = new S3();
    const managedDownloader:ManagedDownloader = new ManagedDownloader(s3);

    const params:GetObjectStreamInput = {
        Bucket: 'example-bucket',
        Key: 'example-key'
    };
    // create a write stream for a file
    const writeStream:fs.WriteStream = fs.createWriteStream('example-file-path');
    
    managedDownloader.getObjectStream(params)
    .then((stream) => {
        stream.pipe(writeStream);
    }, (err) => {
        writeStream.end();
        console.error(err);
    });

2. Use the Managed Download object to create a download stream for a range of bytes of a file on S3

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'.

JavaScript

    const S3 = require('aws-sdk/clients/s3');
    const ManagedDownloader = require('@aws/s3-managed-download').ManagedDownloader;
    const fs = require('fs');
    
    const s3 = new S3();
    const managedDownloader = new ManagedDownloader(s3);

    const params = {
        Bucket: 'example-bucket',
        Key: 'example-key',
        Range: '100-150'
    };
    // create a write stream for a file starting at byte 100
    const writeStream = fs.createWriteStream('example-file-path', {start:100});
    
    managedDownloader.getObjectStream(params)
    .then((stream) => {
        stream.pipe(writeStream);
    }, (err) => {
        writeStream.end();
        console.error(err);
    });

TypeScript

    import * as S3 from 'aws-sdk/clients/s3';
    import { ManagedDownloader, GetObjectStreamInput, ManagedDownloaderOptions } from '@aws/s3-managed-download';
    import * as fs from 'fs';

    const s3:S3 = new S3();
    const managedDownloader:ManagedDownloader = new ManagedDownloader(s3);
    
    const params:GetObjectStreamInput = {
        Bucket: 'example-bucket',
        Key: 'example-key',
        Range: '100-150'
    };
    // create a write stream for a file starting at byte 100
    const writeStream:fs.WriteStream = fs.createWriteStream('example-file-path', {start:100});
    
    managedDownloader.getObjectStream(params)
    .then((stream) => {
        stream.pipe(writeStream);
    }, (err) => {
        writeStream.end();
        console.error(err);
    });

Opening Issues

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.

License

This library is licensed under the Apache 2.0 License.

版本与发布记录

@aws/s3-managed-downloader 共发布 1 个版本,首次发布于 2018/09/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.0latest2018/09/128 年前

关于 @aws/s3-managed-downloader 的常见问题

@aws/s3-managed-downloader 是什么?

Managed Downloader for S3

如何安装 @aws/s3-managed-downloader?

在项目目录运行 npm install @aws/s3-managed-downloader,或使用 pnpm add / yarn add / bun add。

@aws/s3-managed-downloader 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aws__s3-managed-downloader 是否存在。

@aws/s3-managed-downloader 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aws/s3-managed-downloader 可以商用吗?

@aws/s3-managed-downloader 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@aws/s3-managed-downloader 的下载量有多少?

根据 npm 官方下载统计,@aws/s3-managed-downloader 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,891 次,日均约 130 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws/s3-managed-downloader 还在维护吗?

最新版本 0.9.0 发布于 2018/09/12(8 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。