【发布时间】:2022-06-14 22:42:10
【问题描述】:
我在 javascript 中有一个 CAR 文件对象,并希望使用 js-car github 读取它。但我不断收到unexpected end of the file 错误。这是我正在尝试的代码
let arrayBuffer = await files[0].arrayBuffer();
let bytes=new Uint8Array(carFile);
const reader = await CarReader.fromBytes(bytes) //throws error here
const indexer = await CarIndexer.fromBytes(bytes) //throws error here
这个我也累了
let str = await files[0].stream()
const reader = await CarReader.fromIterable(files[0].stream()) //throws error here
它们都不起作用。但是,对于同一个文件,此代码可以工作
const inStream = fs.createReadStream('test.car')
const reader = await CarReader.fromIterable(inStream)
我查过,我知道CarReader.fromBytes 需要Unit8Arrey,我确信files[0] 不为空。有谁知道我在这里缺少什么?
【问题讨论】:
标签: javascript file uint8array