Skip to content

Commit 50a4c80

Browse files
authored
feat: expose allowBigBlock option (#227)
To allow adding large blocks to the blockstore, expose the `--allow-big-block` flag from `ipfs block put`.
1 parent bf3fac4 commit 50a4c80

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/block/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export interface BlockPutOptions extends HTTPRPCOptions {
2626
* Pin this block when adding. (Defaults to `false`)
2727
*/
2828
pin?: boolean
29+
30+
/**
31+
* Allow creating blocks larger than 1MB
32+
*
33+
* @default false
34+
*/
35+
allowBigBlock?: boolean
2936
}
3037

3138
export interface BlockRmOptions extends HTTPRPCOptions {

test/interface-tests/src/block/put.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { getDescribe, getIt, type MochaConfig } from '../utils/mocha.js'
1010
import type { KuboRPCClient } from '../../../../src/index.js'
1111
import type { KuboRPCFactory } from '../index.js'
1212

13+
const ONE_MEG = 1024 * 1024
14+
1315
export function testPut (factory: KuboRPCFactory, options: MochaConfig): void {
1416
const describe = getDescribe(options)
1517
const it = getIt(options)
@@ -64,5 +66,23 @@ export function testPut (factory: KuboRPCFactory, options: MochaConfig): void {
6466

6567
expect(cid.multihash.bytes).to.equalBytes(expectedCID.multihash.bytes)
6668
})
69+
70+
it('should fail to put a big block', async () => {
71+
await expect(ipfs.block.put(new Uint8Array(ONE_MEG + 1)))
72+
.to.eventually.be.rejected()
73+
.with.property('message')
74+
.that.include('produced block is over 1MiB')
75+
})
76+
77+
it('should put a big block with `allowBigBlock`', async () => {
78+
const expectedHash = 'bafkreibmw5hnxj2uvaorehe5w2btobfi47kbpznrhunbt5fff4ah2zccmq'
79+
const expectedCID = CID.parse(expectedHash)
80+
81+
const cid = await ipfs.block.put(new Uint8Array(ONE_MEG + 1), {
82+
allowBigBlock: true
83+
})
84+
85+
expect(cid.toString()).to.equal(expectedCID.toString())
86+
})
6787
})
6888
}

0 commit comments

Comments
 (0)