内容简介:Turn an aws api call into a readable stream.Piping the result ofTake care to use
aws-api-read-stream
Turn an aws api call into a readable stream.
Install
npm i aws-api-read-stream
example
Piping the result of s3.listObjectsV2()
Take care to use NextToken
or ContinuationToken
accordingly.
const aws = require('aws-sdk') const APIStream = require('aws-api-read-stream') const { promisify } = require('util') const pipeline = promisify(require('stream').pipeline) async function main() { const s3 = new aws.S3() const s = APIStream.from((nextToken) => { return s3.listObjectsV2({ Bucket: 'your-bucket-here', ContinuationToken: nextToken }).promise() }) // convert the object stream to strings using async generator const transform = async function*(source) { for await (const chunk of source) { yield JSON.stringify(chunk) } } await pipeline(s, transform, process.stdout) } main()
Keep reading until the stream finishes. This will buffer the results in an internal array
const aws = require('aws-sdk') const APIStream = require('aws-api-read-stream') const { promisify } = require('util') const pipeline = promisify(require('stream').pipeline) async function main() { const s3 = new aws.S3() const s = APIStream.from((nextToken) => { return s3.listObjectsV2({ Bucket: 'your-bucket-here', ContinuationToken: nextToken }).promise() }) const results = await s.readAll() } main()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Effective C++
梅耶 (Scott Meyers) / 侯捷 / 电子工业出版社 / 2011-1-1 / 65.00元
《Effective C++:改善程序与设计的55个具体做法(第3版)(中文版)(双色)》内容简介:有人说C++程序员可以分为两类,读过Effective C++的和没读过的。世界项级C++大师scott Meyers成名之作的第三版的确当得起这样的评价。当您读过《Effective C++:改善程序与设计的55个具体做法(第3版)(中文版)(双色)》之后,就获得了迅速提升自己C++功力的一个契机......一起来看看 《Effective C++》 这本书的介绍吧!