Skip to content

Commit

Permalink
feat: upgrade deps for blob
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jun 3, 2024
1 parent 0de22d2 commit 5a0ccad
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 275 deletions.
23 changes: 23 additions & 0 deletions can.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ import {
parseCarLink,
} from './lib.js'

/**
* @param {string} blobPath
*/
export async function spaceBlobAdd(blobPath) {
const client = await getClient()

const spinner = ora('Reading CAR').start()
/** @type {Blob} */
let blob
try {
const data = await fs.promises.readFile(blobPath)
blob = new Blob([data])
} catch (/** @type {any} */ err) {
spinner.fail(`Error: failed to read Blob: ${err.message}`)
process.exit(1)
}

spinner.start('Storing')
const cid = await client.capability.blob.add(blob)
console.log(cid.toString())
spinner.stopAndPersist({ symbol: '⁂', text: `Stored ${cid}` })
}

/**
* @param {string} carPath
*/
Expand Down
8 changes: 5 additions & 3 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export async function readProofFromBytes(bytes) {
* @param {boolean} [opts.raw]
* @param {boolean} [opts.json]
* @param {boolean} [opts.shards]
* @param {boolean} [opts.plainTree]
* @returns {string}
*/
export function uploadListResponseToString(res, opts = {}) {
Expand All @@ -193,16 +194,17 @@ export function uploadListResponseToString(res, opts = {}) {
.join('\n')
} else if (opts.shards) {
return res.results
.map(({ root, shards }) =>
tree({
.map(({ root, shards }) => {
const treeBuilder = opts.plainTree ? tree.plain : tree
return treeBuilder({
label: root.toString(),
nodes: [
{
label: 'shards',
leaf: shards?.map((s) => s.toString()),
},
],
})
})}
)
.join('\n')
} else {
Expand Down
Loading

0 comments on commit 5a0ccad

Please sign in to comment.