ipld / js-car

Content Addressable aRchive format reader and writer for JavaScript
Other
46 stars 7 forks source link

Export a version from the writer #161

Closed achingbrain closed 9 months ago

achingbrain commented 9 months ago

From what I can tell, this module will only create v1 CAR files and it doesn't provide a method to obtain the version of the file it's creating - please let me know if I've missed something obvious.

When returning a CAR file from an HTTP Gateway the spec says the Content-Type header should include the version number, e.g:

Content-Type: application/vnd.ipld.car; version=1

It'd be great if we could hand that off to the writer, to reduce the chance of it getting messed up, something like:

const { writer, out } = CarWriter.create(cid)

const response = new Response(out, {
  status: 200
})
response.headers.set('content-type', `application/vnd.ipld.car; version=${writer.version()}`)
rvagg commented 9 months ago

Yeah, strictly only v1 and as yet I've not seen a compelling reason to do v2 in JS except for if someone wants to make a blockstore; although I think web3.storage has an implementation that uses v2 with indexes for something to do with unixfs paths.

Feel free to add a version field, or a method if you think that makes more sense, it can just return a const 1 for now.