在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/ipfsx开源软件地址:https://github.com/ipfs-shipyard/ipfsx开源编程语言:JavaScript 100.0%开源软件介绍:ipfsx
Table of ContentsBackgroundJS IPFS supports two types of stream at the API level, but uses pull streams for internals. If I was working on js-ipfs at the time I'd have made the same decision. Since then, async/await became part of the JS language and the majority of JavaScript runtimes now support async/await, async iterators and for/await/of (i.e. no need to transpile). These tools give us the power to stream data without needing to rely on a library. Just because there are new language features available doesn't mean we should switch to using them. It's a significant upheaval to change the core interface spec and it's implementations (js-ipfs, js-ipfs-api etc.) without good reason. That is why this repository exists: it provides a playground where we can test out new API ideas without having to set them in stone by writing them in the spec. The big changes are to switch to async/await syntax and to make use of async iterators in place of Node.js/pull streams. I want JS IPFS to feel modern, up to date and cutting edge and I'm willing to bet that this will aid community contributions and adoption. Part of the reason I'm pro switching to async iterators is because I see parallels between them and pull streams, and I'm super pro pull streams for their simplicity and power:
There's actually a bunch of other good reasons to switch to async/await and async iterators:
Something for your consideration - async/await is inevitable for js-ipfs and js-ipfs-api, the CLI tests are already all promise based, when we inevitably upgrade to Hapi 17 the HTTP API will have to become promise based. The whole of the core interface is dual callback/promise based through Specific rationale for deviations from the Installnpm install ipfsx Usageimport ipfsx from 'ipfsx'
import IPFS from 'ipfs' // N.B. also works with ipfs-api!
const node = await ipfsx(new IPFS)
// IPFS node now ready to use!
// Add something to IPFS
const { cid } = await node.add('hello world').first()
// Stream content from IPFS using async iterators
let data = Buffer.alloc(0)
for await (const chunk of node.cat(cid)) {
data = Buffer.concat([data, chunk])
}
// for more, see API below API
ContributeFeel free to dive in! Open an issue or submit PRs. LicenseMIT © Protocol Labs |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论