stream-to-promise stream 2 promise 的npm 包
好处就是简化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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2020-01-25 poolifier nodejs 线程池工具
2019-01-25 openresty 集成 sentry 异常系统
2019-01-25 quicklink 基本使用
2019-01-25 pnpm 快速节省磁盘工具的包管理工具
2019-01-25 Load Balancing OpenSSH SFTP with HAProxy
2016-01-25 Centos配置国内yum源
2016-01-25 ubutntu apt 源