Skip to content

Commit

Permalink
feat: expose allowBigBlock option (#227)
Browse files Browse the repository at this point in the history
To allow adding large blocks to the blockstore, expose the `--allow-big-block`
flag from `ipfs block put`.
  • Loading branch information
achingbrain authored Apr 23, 2024
1 parent bf3fac4 commit 50a4c80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export interface BlockPutOptions extends HTTPRPCOptions {
* Pin this block when adding. (Defaults to `false`)
*/
pin?: boolean

/**
* Allow creating blocks larger than 1MB
*
* @default false
*/
allowBigBlock?: boolean
}

export interface BlockRmOptions extends HTTPRPCOptions {
Expand Down
20 changes: 20 additions & 0 deletions test/interface-tests/src/block/put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js'
import type { KuboRPCClient } from '../../../../src/index.js'
import type { KuboRPCFactory } from '../index.js'

const ONE_MEG = 1024 * 1024

export function testPut (factory: KuboRPCFactory, options: MochaConfig): void {
const describe = getDescribe(options)
const it = getIt(options)
Expand Down Expand Up @@ -64,5 +66,23 @@ export function testPut (factory: KuboRPCFactory, options: MochaConfig): void {

expect(cid.multihash.bytes).to.equalBytes(expectedCID.multihash.bytes)
})

it('should fail to put a big block', async () => {
await expect(ipfs.block.put(new Uint8Array(ONE_MEG + 1)))
.to.eventually.be.rejected()
.with.property('message')
.that.include('produced block is over 1MiB')
})

it('should put a big block with `allowBigBlock`', async () => {
const expectedHash = 'bafkreibmw5hnxj2uvaorehe5w2btobfi47kbpznrhunbt5fff4ah2zccmq'
const expectedCID = CID.parse(expectedHash)

const cid = await ipfs.block.put(new Uint8Array(ONE_MEG + 1), {
allowBigBlock: true
})

expect(cid.toString()).to.equal(expectedCID.toString())
})
})
}

0 comments on commit 50a4c80

Please sign in to comment.