-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: upload/list items have a shards array property (#229)
- update tests and types to handle upload/list items with a shards array property. - update upload/add fn to return an UploadAddResponse as shards out may be more than shards in. - update README see also: storacha/w3infra#56 Signed-off-by: Oli Evans <[email protected]>
- Loading branch information
Showing
8 changed files
with
106 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CarWriter } from '@ipld/car' | ||
import { CID } from 'multiformats/cid' | ||
import * as raw from 'multiformats/codecs/raw' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
import * as CAR from '@ucanto/transport/car' | ||
|
||
/** | ||
* @param {Uint8Array} bytes | ||
**/ | ||
export async function toCAR(bytes) { | ||
const hash = await sha256.digest(bytes) | ||
const root = CID.create(1, raw.code, hash) | ||
|
||
const { writer, out } = CarWriter.create(root) | ||
writer.put({ cid: root, bytes }) | ||
writer.close() | ||
|
||
const chunks = [] | ||
for await (const chunk of out) { | ||
chunks.push(chunk) | ||
} | ||
const blob = new Blob(chunks) | ||
const cid = await CAR.codec.link(new Uint8Array(await blob.arrayBuffer())) | ||
|
||
return Object.assign(blob, { cid, roots: [root] }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters