Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
leer el archivo CAR usando js-car

Tengo un objeto de archivo CAR en javascript y quiero leerlo usando js-car github . Pero sigo recibiendo unexpected end of the file . Aquí está mi código que estoy intentando

 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

yo también cansé esto

 let str = await files[0].stream() const reader = await CarReader.fromIterable(files[0].stream()) //throws error here

y ninguno de ellos trabaja. Sin embargo, con el mismo archivo, este código funciona.

 const inStream = fs.createReadStream('test.car') const reader = await CarReader.fromIterable(inStream)

Revisé y sé que CarReader.fromBytes necesita un Unit8Arrey y estoy seguro de que los files[0] no son nulos. ¿Alguien sabe lo que me estoy perdiendo aquí?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

para las personas que podrían enfrentar un problema similar en el futuro, esta es mi solución: usé res.body directamente y lo convertí en una async stream y lo leí usando fromIterable

 async function* streamAsyncIterator(stream) { // Get a lock on the stream const reader = stream.getReader(); try { while (true) { // Read from the stream const { done, value } = await reader.read(); // Exit if we're done if (done) return; // Else yield the chunk yield value; } } finally { reader.releaseLock(); } } const info = await w3StorageClient.status(response) if (info) { // Fetch and verify files from web3.storage const res = await w3StorageClient.get(response); const reader = await CarReader.fromIterable(streamAsyncIterator(res.body)) // read the list of roots from the header const roots = await reader.getRoots() // retrieve a block, as a { cid:CID, bytes:UInt8Array } pair from the archive const got = await reader.get(roots[0]) // also possible: for await (const { cid, bytes } of CarIterator.fromIterable(inStream)) { ... } let decoded = cbor.decode(got.bytes) console.log('Retrieved [%s] from example.car with CID [%s]', decoded, roots[0].toString()) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!