Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: automatic client side CAR chunking for large data (#588)
`storeBlob`, `storeDirectory` and `store` now construct CAR files and then call `storeCar` (which `POST`s to `/upload`). This automatically gives them CAR chunking capability. It adds the following **static** functions: ```ts NFTStorage.encodeBlob(blob: Blob): Promise<{ cid: CID, car: CarReader }> NFTStorage.encodeDirectory(files: Blob[]): Promise<{ cid: CID, car: CarReader }> NFTStorage.encodeNFT<T extends TokenInput>(input: T): Promise<{ cid: CID, token: Token<T>, car: CarReader }> ``` After encoding your CAR and obtaining the root CID you can call: ```js await client.storeCar(car) ``` 🚨 There are trade offs here: 1. We're always sending CAR files so our `type` field is going to always be `Car` for uploads from the JS client. To mitigate this we could simply inspect the root node of the CAR, from this we can assertain the type of the data. We should talk about our `type` field and what it means. Right now we've mapped it to the method of upload...lets resolve this and submit a separate PR to fix. FYI, I'm going to be implementing [#355](#355) soon so will be inspecting the root node of the CAR anyway for validation purposes. 2. The `files` property is not set for the `Multipart` or `Nft` type uploads (since it's being uploaded as a CAR). I actually can't see any requests to the `/status/:cid` API (literally 0 - everyone uses `/check/:cid`) in the cloudflare logs which is the only place this data is exposed to users. I don't think folks will miss it. However if we inspect the root node we can get a shallow directory listing to put here. For `Nft` types we can't really set it anymore. There's also a regression right now where we're _not_ setting it anyway. As an aside I'm not sure how much value it has since the data is just a list of file names, without paths within the object that is created... resolves #220
- Loading branch information