multiformats / multiformats/js-multiformats
Make block size limit part of the BlockEncoder API
Open
@Gozala is already working on this.
Since Dec 6, 2022.
- Dominant language
- TypeScript
- Stars
- 268
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
Currently BlockEncoder interface just encodes passed input into bytes
Problem is:
- If you go beyond block size limit, your block won't be bit-swappable.
- You may not even know you've gone past block size limit.
- Most people is not even aware of the block size limit.
Proposed solution:
I would like to propose amending our BlockEncoder interface as follows:
export interface BlockEncoder<Code extends number, T> {
name: string
code: Code
/**
* Encodes given data. If `buffer` is provided data is written into it and
* a `Uint8Array` view of the written bytes is returned. If `buffer` is not
* passed new buffer is allocated with a `byteLength` corresponding to
* default block size limit in IPFS. If encoded data does not fit the `buffer`
* `RangeError` exception is thrown.
*/
encode: (data: T, buffer?: Uint8Array) => ByteView<T>
}
Idea here is that:
- User should be able to optionally pass in the buffer to write data into.
- If data does not fit the block size limit encode fails.
- User is still able to encode blocks larger than a block size limit by passing in larger buffer.
This will be non-breaking change at the API level, but it would be breaking in the sense that errors will occur if block is larger than a block size limit. Never the less it seems like a better default than silently letting things slip.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.