multiformats / js-cid

CID implementation in JavaScript
MIT License
97 stars 39 forks source link

Multicodec constants #72

Closed vmx closed 4 years ago

vmx commented 5 years ago

The codec used to be defined as string. Now you can use the numbers as defined per multicodec constants. The codec is stored in a field called code.

Ideally we would store it in codec, but for backwards compatibility reasons that one will still return the name of the codec as a string.

New code should use code instead of codec to check for the codec a CID is using.

This change needs https://github.com/multiformats/js-multicodec/pull/35 to be merged first.

achingbrain commented 5 years ago

FWIW, I vastly prefer the DX of using strings rather than numbers.

vmx commented 5 years ago

@achingbrain From the DX it's is string vs. constants.

achingbrain commented 5 years ago

Yes, but the constants are numbers, which opens the door to new CID(1, 7, mh) as @alanshaw points out.

vmx commented 5 years ago

which opens the door to new CID(1, 7, mh)

Which is the whole point in order to make custom IPLD Formats easier to add (writing down why I want this is on my TODO list).

vmx commented 4 years ago

This effort is superseded by https://github.com/multiformats/js-multiformats, which does exactly that. Thanks @mikeal for picking up that idea.