@adobe/httptransfer

中文文档
5.0.0发布于 2025/03/20Apache-2.0CommonJS近 30 天下载 1.6万

节点JS高效文件传输模块

中文使用文档
文档目录14 节
  1. 导言
  2. 安装
  3. 使用流
  4. 使用文件
  5. 使用块上传/下行区域同时上传/下行文件
  6. 调试
  7. 测试台
  8. 构建
  9. Azure 证书
  10. 实例
  11. 端到端测试
  12. 端到端块上传/下载测试
  13. 捐款
  14. 许可证发放

节点- httptransfer

Version

导言

这个 node-httptransfer 软件包的设计是为了方便和正确地将文件内容从HTTP(S) urls转移到HTTP(S) urls之间以及HTTP(S) urls之间.

下等流 API 允许您将内容从 URL 传输到任何可写流, 并且同样将任何可读流传输到 URL .

高级文件 API 摘要将流移出, 并允许您将内容传输到磁盘上的文件 .

这个 node-httptransfer 软件包需要async/await特性,并使用 节点比对npm 软件包.

要使用块传输能力,上传/下载服务器必须支持范围头.

安装

npm i @adobe/httptransfer

使用流

下载流 :

const { downloadStream } = require('@adobe/httptransfer');
async main() {
    const stream = fs.createWriteStream('test.png');
    await downloadStream('http://my.server.com/test.png', stream);
}

使用 PUT 上传流 :

const { uploadStream } = require('@adobe/httptransfer');
async main() {
    const stream = fs.createReadStream('test.png');
    await uploadStream(stream, 'http://my.server.com/test.png');
}

使用文件

下载文件 :

const { downloadFile } = require('@adobe/httptransfer');
async main() {
    await downloadFile('http://my.server.com/test.png', 'test.png');
}

使用 PUT 上传文件 :

const { uploadFile } = require('@adobe/httptransfer');
async main() {
    await uploadFile('test.png', 'http://my.server.com/test.png');
}

使用 PUT( 由 AEM 多段上传使用) 上传到多个 URL 的文件 :

const { uploadAEMMultipartFile } = require('@adobe/httptransfer');
async main() {
    await uploadAEMMultipartFile('test.png', {
        urls: [ "http://my.server.com/test.png.1", "http://my.server.com/test.png.2" ],
        maxPartSize: 1000000
    });
}

使用块上传/下行区域同时上传/下行文件

const { downloadFileConcurrently } = require('@adobe/httptransfer');
async main() {
    await downloadFile('http://my.server.com/test.png', 'test.png');
}

使用 PUT 上传文件 :

const { uploadFileConcurrently } = require('@adobe/httptransfer');
async main() {
    await uploadFile('test.png', 'http://my.server.com/test.png');
}

使用 PUT( 由 AEM 多段上传使用) 上传到多个 URL 的文件 :

const { uploadMultiPartFileConcurrently } = require('@adobe/httptransfer');
async main() {
    await uploadMultiPartFileConcurrently('test.png', {
        urls: [ "http://my.server.com/test.png.1", "http://my.server.com/test.png.2" ],
        maxPartSize: 1000000
    });
}

使用 PUT 上传多个文件到多个 URL :

const { uploadFilesConcurrently } = require('@adobe/httptransfer');
async main() {
    await uploadFilesConcurrently([{
        filepath: 'file1.png',
        target: {
            urls: [ "http://my.server.com/file1.png.1", "http://my.server.com/file1.png.2" ],
            maxPartSize: 1000000
        }
    }], {
        filepath: 'file2.png',
        target: {
            urls: [ "http://my.server.com/file2.png.1", "http://my.server.com/file2.png.2" ],
            maxPartSize: 1000000
        }
    }]);
}

假设 test.png 1,800,000个字节将上传到 http://my.server.com/test.png.1 后80万字节改为 http://my.server.com/test.png.2。 。 。 .

调试

在使用时启用调试输出 node-httptransfer 库,设置 DEBUG 环境变量改为 httptransfer:*。 。 。 . 您也可以指定每个日志级别 ./lib/logger.js (英语),例如:

$ DEBUG='httptransfer:warn' npm run test

测试台

CLI 工具 测试床 用于测试 node-httptransfer 函数。 它支持上传,下载,以及转移文件内容. 它还通过在苍蝇上创建的共享访问签名(SAS)urls支持Azure Blob商店.

该工具并不打算单独有用,只是为了测试新特性或调试问题.

构建

cd testbed/
npm install

Azure 证书

export AZURE_STORAGE_ACCOUNT=<storage account name from https://portal.azure.com>
export AZURE_STORAGE_KEY=<storage key from https://portal.azure.com>

实例

从网站上下载图像 :

node index.js https://website.com/path/to/image.gif image.gif

从 Azure 下载 blob.txt :

node index.js azure://container/path/to/blob.txt blob.txt

上传 blob.txt 到 azure :

node index.js blob.txt azure://container/path/to/blob.txt

以一万字节块上传 blob.txt :

node index.js --max 10000 blob.txt azure://container/path/to/blob.txt

在容器内复制 blob.txt :

node index.js azure://container/path/to/blob.txt azure://container/path/to/target.txt

端到端测试

该模块为验证基本传输功能提供了一些集成式测试 与 Adobe 经验管理器实例。 为了进行测试:

  • 创建一个 .env 通过遵循在 .env 实例。 。 。 .
  • 通过执行运行测试 npm run e2e 从寄存器的根目录.

端到端块上传/下载测试

如果你想只是运行块上传/下载测试,只需要 Azure 证书数字 :

export AZURE_STORAGE_ACCOUNT=<storage account name from https://portal.azure.com>
export AZURE_STORAGE_KEY=<storage key from https://portal.azure.com>
export AZURE_STORAGE_CONTAINER_NAME=<storage container name>

运行 npm run e2e-block

捐款

欢迎捐款! 读取 贡献指南 更多信息.

许可证发放

这个项目根据Apache V2许可证获得许可. 见 自由主义 更多信息.

版本与发布记录

@adobe/httptransfer 共发布 37 个版本,首次发布于 2020/04/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2025/03/201.6 年前
4.0.12025/03/201.6 年前
4.0.02024/06/012 年前
3.4.12023/07/263 年前
3.4.02023/06/033 年前
3.3.12023/05/263 年前

关于 @adobe/httptransfer 的常见问题

@adobe/httptransfer 是什么?

节点JS高效文件传输模块

如何安装 @adobe/httptransfer?

在项目目录运行 npm install @adobe/httptransfer,或使用 pnpm add / yarn add / bun add。

@adobe/httptransfer 支持 TypeScript 吗?

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

@adobe/httptransfer 支持 ESM 还是 CommonJS?

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

@adobe/httptransfer 可以商用吗?

@adobe/httptransfer 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/httptransfer 的下载量有多少?

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

@adobe/httptransfer 还在维护吗?

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