Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert "feat: upload-client funcs have options.piece to opt in to piece link calculation (#1220) #1224

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/upload-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ async function uploadBlockStream(conf, blocks, options = {}) {
const bytes = new Uint8Array(await car.arrayBuffer())
const [cid, piece] = await Promise.all([
Store.add(conf, bytes, options),
options.piece
? (async () => {
const multihashDigest = await PieceHasher.digest(bytes)
return /** @type {import('@web3-storage/capabilities/types').PieceLink} */ (
Link.create(raw.code, multihashDigest)
)
})()
: undefined,
(async () => {
const multihashDigest = await PieceHasher.digest(bytes)
return /** @type {import('@web3-storage/capabilities/types').PieceLink} */ (
Link.create(raw.code, multihashDigest)
)
})(),
])
const { version, roots, size } = car
return { version, roots, size, cid, piece }
Expand Down
4 changes: 1 addition & 3 deletions packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export interface CARMetadata extends CARHeaderInfo {
*
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
piece?: PieceLink
piece: PieceLink
/**
* Size of the CAR file in bytes.
*/
Expand Down Expand Up @@ -253,8 +253,6 @@ export interface UploadOptions
ShardStoringOptions,
UploadProgressTrackable {
onShardStored?: (meta: CARMetadata) => void
/** when true, uploading will calculate filecoin piece link */
piece?: true
}

export interface UploadDirectoryOptions
Expand Down
25 changes: 3 additions & 22 deletions packages/upload-client/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,36 +705,17 @@ describe('uploadCAR', () => {
car,
{
connection,
onShardStored: (meta) => meta.piece && pieceCIDs.push(meta.piece),
onShardStored: (meta) => pieceCIDs.push(meta.piece),
}
)

assert(service.store.add.called)
assert.equal(service.store.add.callCount, 1)
assert(service.upload.add.called)
assert.equal(service.upload.add.callCount, 1)
// pieceCID calculation is disabled by default
assert.equal(pieceCIDs.length, 0)

// can opt in to calculating piece link
/** @type {Array<import('@web3-storage/upload-client/types').CARMetadata>} */
const shards2 = []
await uploadCAR(
{ issuer: agent, with: space.did(), proofs, audience: serviceSigner },
car,
{
connection,
onShardStored: (meta) => shards2.push(meta),
piece: true,
}
)
assert.equal(shards2.length, 1)
assert.ok(
shards2[0].piece,
'shard piece cid is truthy because options.piece=true'
)
assert.equal(pieceCIDs.length, 1)
assert.equal(
shards2[0].piece.toString(),
pieceCIDs[0].toString(),
'bafkzcibcoibrsisrq3nrfmsxvynduf4kkf7qy33ip65w7ttfk7guyqod5w5mmei'
)
})
Expand Down
Loading