Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upfeat: allow CID by codec name where registered in multiformats #12
Conversation
| mapper = i => { | ||
| const name = `new CID(${i}, 112, buffer)` | ||
| test(name, () => testThrowAny(new CID(i, 112, hash))) | ||
| test(name, () => testThrowAny(() => new CID(i, 112, hash))) |
This comment has been minimized.
This comment has been minimized.
rvagg
Jun 2, 2020
Author
Contributor
wasn't being tested properly, I guess this is where the error message checking of throws() comes in handy
|
This warrants some discussion. I actually had this feature in mind when I started the implementation and then decided against it. The reason I cut it was the same reason I fully deprecated the The big shift people have to make with the new interface is thinking of a CID as a reference to something they may not know how to consume. Allowing the string name opens the door to people publishing libraries that don’t work unless you include codec support for something that you’re never actually encoding/decoding just because they wanted to use the string name to create CID instances. Given that the But there may be some usage I’m not considering here and am open to talking more about it. |
|
OK, so for anyone else reading this - we both agree that this piece of So we'll shelve this for now and assess how the API ends up being used when we have all the pieces in place. |
rvagg commentedJun 2, 2020
I found a pattern I kept reaching for was this so I didn't have to repeat magic numbers or their constants everywhere:
new multiformats.CID(1, multiformats.get('codec-name').code, hash). This PR does that insideCID, restoring the ability to supply a string codec name where multiformats has that string->code mapping registered.Also adds some more type checking.