我试图通过ipfs-car
(使用Web流)打包CAR文件,然后将其作为文件发送到请求中,但我不确定如何在WritableStream
中流式传输后将其存储在Blob
中。
我有一段代码
import { CAREncoderStream, createDirectoryEncoderStream } from 'ipfs-car'
import { WritableStream } from 'node:stream/web'
export const packCAR = async (files) => {
const blockStream = createDirectoryEncoderStream(files)
const carEncoderStream = new CAREncoderStream([])
const outStream = new WritableStream()
await blockStream.pipeThrough(carEncoderStream).pipeTo(outStream)
const blob = new Blob(/* what do I put here? */)
}
我还没有找到任何人这样做,我只看到了如何将Blob
转换为流,所以帮助将不胜感激:)
1条答案
按热度按时间lnxxn5zx1#
将WritableStream的内容存储到Blob中。这可以通过将WritableStream转换为ReadableStream,然后将其转换为ArrayBuffer,最后将ArrayBuffer存储到Blob中来完成。