使用JS卡车读取汽车文件
我在JavaScript中有一个CAR
文件对象,并希望使用js-car
github 。但是我不断获得文件的意外结尾
错误。这是我正在尝试的代码,
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]
是不是零。有人知道我在这里缺少什么吗?
I have a CAR
file object in javascript and want to read it using js-car
github. But I keep getting unexpected end of the file
error. Here is my code I am trying
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
I also tired this
let str = await files[0].stream()
const reader = await CarReader.fromIterable(files[0].stream()) //throws error here
and none of them work. However with the same file this code works
const inStream = fs.createReadStream('test.car')
const reader = await CarReader.fromIterable(inStream)
I checked and I know that CarReader.fromBytes
needs a Unit8Arrey
and I am sure files[0]
is not null. Does anyone knows what I am missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为人们将来可能会面临类似的问题,这是我的解决方案:
我直接使用了
res.body
,然后将其转换为async stream
,然后使用Fromiterable
读取它。for the people might face similar issue in future this is my solution:
I used
res.body
directly and converted it to anasync stream
and read it usingfromIterable