首页 > 其他 > 详细

stream-to-promise stream 2 promise 的npm 包

时间:2021-01-26 00:44:24      阅读:29      评论:0      收藏:0      [点我收藏+]

好处就是简化callback的处理,以下是关于minio listobjects 的使用

参考代码

  • pacakge.json
{
  "name": "app",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "minio": "^7.0.18",
    "stream-to-promise": "^3.0.0"
  }
}
  • app.js
const Minio = require(‘minio‘)
const streamToPromise = require(‘stream-to-promise‘) 
const minioClient = new Minio.Client({
    endPoint: ‘play.min.io‘,
    port: 80,
    useSSL: false,
    accessKey: ‘Q3AM3UQ867SPQQA43P2F‘,
    secretKey: ‘zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG‘
});
?
(async ()=>{
  var result = await  streamToPromise(minioClient.listObjectsV2("005-bucket","",true))
  console.log("exec 1")
  console.log(result)
})()
?
streamToPromise(minioClient.listObjectsV2("005-bucket","",true)).then(function(data){
    console.log("exec 2")
    console.log(data)
})

说明

通过stream-to-promise我们可以简化stream模式的数据访问

参考资料

https://github.com/bendrucker/stream-to-promise
https://docs.min.io/docs/javascript-client-quickstart-guide.html

stream-to-promise stream 2 promise 的npm 包

原文:https://www.cnblogs.com/rongfengliang/p/14327997.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!