...
 
Commits (83)
    https://gitlab.dms3.io/dms3/go-cidutil/-/commit/ce2167fed18d585c36cd5d1f45ef6ebe2f68d751 some improvements from integrating into go-ipfs 2016-08-31T19:47:09-07:00 Jeromy why@ipfs.io https://gitlab.dms3.io/dms3/go-cidutil/-/commit/35c32d5226208e5149ac0809339142e20d4890b6 add some more helper functions to ease integration into go-ipfs 2016-09-01T15:46:36-07:00 Jeromy why@ipfs.io https://gitlab.dms3.io/dms3/go-cidutil/-/commit/cdef63fb9421de80f626ba3f3873d3f54f8bcad6 add 'Prefix' object and some more helper routines 2016-10-08T21:17:59-07:00 Jeromy why@ipfs.io https://gitlab.dms3.io/dms3/go-cidutil/-/commit/bae78f13f8226c3e2ae24267b1595734a9caa2f6 add an example to the tests to play around with the feature 2017-03-18T19:17:44-07:00 Jeromy jeromyj@gmail.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/9eb57afccb621fb0d24ae1eef73ed03f267fe5bc Readme/golint: improve readme with gx instructions. Make golint happy. 2017-03-24T15:12:07+01:00 Hector Sanjuan hector@protocol.ai License: MIT Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:hector@protocol.ai" title="hector@protocol.ai"><img alt="default avatar" src="https://secure.gravatar.com/avatar/ceba6874e0cb51a9a9063fb345be8042?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:hector@protocol.ai" title="hector@protocol.ai">Hector Sanjuan</a> &lt;<a href="mailto:hector@protocol.ai" title="hector@protocol.ai">hector@protocol.ai</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/1323cde2b7d03a286e22ce351dd7edd0de3e4258 Merge pull request #17 from ipfs/doc-improvements 2017-03-24T17:10:15+01:00 Jakub Sztandera kubuxu@protonmail.ch Readme/golint: improve readme with gx instructions. Make golint happy. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/ff66ebf69f208b05220fd8a79d2af90a2f884aa1 Implement basic 'cid-fmt' utility. 2017-08-15T03:46:48-04:00 Kevin Atkinson k@kevina.org Currently only implements printing the Cid prefix. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/335a9b896b60cfd179a0bdf05d08d1d5185512bc Implement 'cid-fmt' utility. 2017-08-15T14:26:24-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/072fed05435612336a070118d38ad72b46ce9372 Add ability to change CID version. 2017-08-15T15:34:15-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/f68dad169945b10d2c00ba50d338f353e8a5d2e8 Use an exit code of 1 on non-fatal errors and 2 on fatal errors. 2017-08-15T17:23:44-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/ffec3ee968edc6dbc26bb9c6fabc65ebbb757157 Merge pull request #31 from ipfs/kevina/cid-fmt 2017-08-28T16:56:05-07:00 Steven Allen steven@stebalien.com Implement 'cid-fmt' utility. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/e9d41995b231cf562f5447cfb7e1b2eb14aa5501 gx: update multibase 2017-08-28T20:17:55-07:00 Steven Allen steven@stebalien.com And fix test case. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/b2038702dda3520191fce515481435a754142faa Merge pull request #33 from ipfs/gx/update-multibase 2017-08-28T20:22:53-07:00 Steven Allen steven@stebalien.com gx: update multibase https://gitlab.dms3.io/dms3/go-cidutil/-/commit/fcbf84a5cb8655bc3f275ca92b2b56e5e10901e1 Create new Format interface for creating CIDs. 2018-06-28T22:48:56-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/581df307016fb7cdccf057373714373235f9c623 Add WithCodec and GetCodec methods to format interface. 2018-07-24T22:28:19-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/06d2604d3f57182824c54e7e681bc32d8be0dba3 Use lookup table in go-multibase now that it is supported. 2018-07-31T16:33:41-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/0abc0a2f97b44fc6f874f75e907c62573147c588 Use new Encoder in multibase package. 2018-07-31T17:07:49-04:00 Kevin Atkinson k@kevina.org This allows multibase codes to be specified by the name rather than just the prefix char. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/7734dbbec6ec351fc757b565ce99cf83ce4464ff Fix fmtRef string. 2018-07-31T17:12:16-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/01620693d8cb42cfbda83893b37f65bb2293308f Clean up cid-fmt util code. 2018-07-31T22:10:47-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/eb97b6f313fdf9d566ecfdf1551eab7edfb47d48 Extract most of `cid-fmt` logic so it can be used as a library. 2018-08-01T04:21:32-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/0d4d6b33644f42632bef71ef6de0811487ee571d Add tests for Set type 2018-08-02T11:51:05+02:00 Hector Sanjuan hector@protocol.ai License: MIT Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:hector@protocol.ai" title="hector@protocol.ai"><img alt="default avatar" src="https://secure.gravatar.com/avatar/ceba6874e0cb51a9a9063fb345be8042?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:hector@protocol.ai" title="hector@protocol.ai">Hector Sanjuan</a> &lt;<a href="mailto:hector@protocol.ai" title="hector@protocol.ai">hector@protocol.ai</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/e0fddd4a336253d24dc3f2b1e83476d1c5052170 Merge pull request #63 from ipfs/tests/set 2018-08-02T19:25:20+00:00 Steven Allen steven@stebalien.com Add tests for Set type https://gitlab.dms3.io/dms3/go-cidutil/-/commit/a02d17cfe69ad0eecea71477ee2c4ab23c393cc1 Rename Format to Builder. 2018-08-09T00:15:04-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/2bc018ba88a47561118f85739b02ca0e6f5de562 Replace DecodeV2 with ExtractEncoding 2018-08-09T02:37:09-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/8fca9c23ff1ce56f558f0e4498350d87c5a08c63 Allocate bytes.Buffer directly on the stack. 2018-08-10T17:27:58-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/b260c48e97128451fc06712a96d75ae1474a3498 Merge pull request #53 from ipfs/kevina/format 2018-08-10T17:34:56-04:00 Kevin Atkinson k@kevina.org Create new Builder interface for creating CIDs. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/99995a30c878a138c1a3e7210f6daba4c315d382 Merge pull request #61 from ipfs/kevina/cid-fmt-enhan 2018-08-10T17:35:25-04:00 Kevin Atkinson k@kevina.org cid-fmt Enhancments https://gitlab.dms3.io/dms3/go-cidutil/-/commit/4de263a9fd38e094bd6d75693a753ab01f57f4bc add a streaming CID set 2018-08-10T17:32:43-07:00 Łukasz Magiera magik6k@gmail.com used in <a href="https://github.com/ipfs/go-ipfs/pull/4804" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-ipfs/pull/4804</a> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/6c39b29ce8f133f23dbd20ba3e683cef343ef7df Merge pull request #67 from ipfs/feat/streaming-set 2018-08-11T01:06:53+00:00 Steven Allen steven@stebalien.com add a streaming CID set https://gitlab.dms3.io/dms3/go-cidutil/-/commit/ce4c06c654ec0807e1dd94e924466e1244e7d754 Extract non-core functionality from go-cid into go-cidutil. 2018-08-17T00:45:00-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/b6f51d5939f175abe20e6e6b229d0012281f3423 Add very basic README. 2018-08-17T00:45:00-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/c614d37c78d072bb92df4ae65c1e9d8492f60120 Add Inliner CID Builder. 2018-08-17T18:08:38-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/4709f60d494d1879e18eb1d187eec9b2b47f1eda Rename Inliner to InlineBuilder. 2018-08-21T14:38:56-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/8aa9fde8b1692feb95deff39d47a924309bacd06 Merge pull request #4 from ipfs/kevina/inliner 2018-08-21T14:42:37-04:00 Kevin Atkinson k@kevina.org Add Inliner CID Builder. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/c698dc87873f495ffa31742e96b672e3258b1751 gx publish 0.0.1 2018-08-21T14:56:48-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/f3ca7b9888c856151e8baa8780e2061d8fef20cd gx publish 0.0.2 2018-08-21T15:17:21-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/0e1a8db3f68ef52bccc7ac2ca61ee6b8a183a3a8 gx: commit lastpubver 2018-08-21T17:45:56-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/a0ab751a0126925a0e3f2232675ca3719556a3bc gx update and fix code to use new Cid type 2018-09-11T19:42:30-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/3c667de0cc4a5d210d9b70340c1a42dac040447a gx publish 0.1.0 2018-09-11T19:42:34-04:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/6c3d0c5abdffa1a8f2096c7b3a024d444611e51b gx publish 0.1.1 2018-09-11T20:31:42-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/e23b86098066f763bea69a1bd3175db568a6e243 add a utility method for sorting CID slices 2018-09-23T23:25:28-07:00 Steven Allen steven@stebalien.com fixes <a href="https://github.com/ipfs/go-cid/issues/46" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/issues/46</a> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/60d67ce4b77e8d86253a250f63f3f78baab32116 Merge pull request #5 from ipfs/fix/cid-slice 2018-09-24T06:29:41+00:00 Steven Allen steven@stebalien.com add a utility method for sorting CID slices https://gitlab.dms3.io/dms3/go-cidutil/-/commit/fe89746dc9530c6a9ec997831b781a8c11d10e04 gx publish 0.1.2 2018-11-02T16:56:50-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/4bb0ce1fc6f6cc49d4b1dbb01788c05311e7e13b Add '--filter' option to cid-fmt utility. 2019-01-07T00:12:00-05:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/90ab4c75706b70d5a70fdf226bb84c1797286b29 Create a CID encoder that optionally upgrades a CIDv0 to CIDv1 2019-01-07T16:00:55-05:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/5fac29cf10c74f6d468aac2d3c3ad3f7aa925362 Enable Jenkins CI. 2019-01-07T16:02:45-05:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/bd83ee2de7e55d3f0515b2662328881caa54e59a Enable Travis CI. 2019-01-07T16:11:25-05:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/d5fe12a0506f2d5e09ff7a5c0d964a6341bc332e Merge pull request #10 from ipfs/kevina/multibase4 2019-01-07T15:22:01-08:00 Steven Allen steven@stebalien.com Changes needed for `--cid-base` option in go-ipfs (simplified vesion) https://gitlab.dms3.io/dms3/go-cidutil/-/commit/fe3c380fd63161e21410180ee32dc2a2fda4de42 Fix Travis CI to run all tests. 2019-01-07T19:49:16-05:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/9f6e627e6f849c2bc18815ee0177903ca815c36e Merge pull request #11 from ipfs/kevina/fix-travis-ci 2019-01-07T17:07:24-08:00 Steven Allen steven@stebalien.com Fix Travis CI to run all tests. https://gitlab.dms3.io/dms3/go-cidutil/-/commit/c6b36b1568bd9887d1bbf8f0ec428b06dd0b1b18 gx publish 0.2.0 2019-01-07T21:49:00-05:00 Kevin Atkinson k@kevina.org https://gitlab.dms3.io/dms3/go-cidutil/-/commit/e04b0028ad7d2d465422615080c77ba99a5e142e gx publish 0.2.1 2019-02-20T20:17:49-08:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/7a289d95efee00994339172286cc99120f87b3e9 Add gomod and Travis 2019-03-01T13:59:08+01:00 Jakub Sztandera kubuxu@protonmail.ch License: MIT Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:kubuxu@protonmail.ch" title="kubuxu@protonmail.ch"><img alt="default avatar" src="https://secure.gravatar.com/avatar/d4dfe1f58343e5354836e797e574c29a?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:kubuxu@protonmail.ch" title="kubuxu@protonmail.ch">Jakub Sztandera</a> &lt;<a href="mailto:kubuxu@protonmail.ch" title="kubuxu@protonmail.ch">kubuxu@protonmail.ch</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/4216e2813a74a8da07ed89c9bba6208f9ae121d1 default cidv1 to base32 2019-05-06T10:29:30-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/2f1a02b4a5fdf2b6680b65fabb54ba871013bb2a nit: gofmt 2019-05-06T10:47:32-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/6927839e80f7708a865033a0fe88d84576991765 test default encoder 2019-05-06T16:04:54-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/8d1606fcb49bff2b39e3dfee3b14e860ea6ed911 Merge pull request #13 from ipfs/feat/cidv1-default-base32 2019-05-13T10:54:24-07:00 Steven Allen steven@stebalien.com default cidv1 to base32 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/fdf58ea0da03b6087e14bcce352303c1c0bad32d dep: update go-cid 2019-05-13T10:55:47-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/e528b0cd0ba0264dee449441bfd40db46bfd76f3 doc: add a lead maintainer 2019-09-18T22:14:13-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/feb0a6b8c27c0fddd29f03b7795cc1191b5dc793 test: fix for base32 switch 2019-09-24T16:25:39-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/37a59b195491f6c68b7adaac898c3078f3457b3d gx: remove 2019-09-24T16:27:54-07:00 Steven Allen steven@stebalien.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/88abe33d0ab0c9b4a6b91a26abcd78d8b4b89f32 Merge pull request #16 from ipfs/fix/base32-test 2019-09-24T16:29:21-07:00 Steven Allen steven@stebalien.com test: fix for base32 switch https://gitlab.dms3.io/dms3/go-cidutil/-/commit/f07bf7bbc7e21dc9597d125c27004cbe4ff175ed Bump github.com/multiformats/go-multihash from 0.0.1 to 0.0.8 2019-09-24T23:30:46+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/multiformats/go-multihash](<a href="https://github.com/multiformats/go-multihash" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash</a>) from 0.0.1 to 0.0.8. - [Release notes](<a href="https://github.com/multiformats/go-multihash/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/releases</a>) - [Commits](<a href="https://github.com/multiformats/go-multihash/compare/v0.0.1...v0.0.8" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/compare/v0.0.1...v0.0.8</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/169d093c805d03808165a61810b8cd3bfaeab6e7 Merge pull request #15 from ipfs/dependabot/go_modules/github.com/multiformat... 2019-09-24T16:39:39-07:00 Steven Allen steven@stebalien.com Bump github.com/multiformats/go-multihash from 0.0.1 to 0.0.8 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/d793f02aa5e8c5b60342609a8cf19ff6f416f29d Bump github.com/ipfs/go-cid from 0.0.2 to 0.0.3 2019-09-24T23:41:03+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/ipfs/go-cid](<a href="https://github.com/ipfs/go-cid" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid</a>) from 0.0.2 to 0.0.3. - [Release notes](<a href="https://github.com/ipfs/go-cid/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/releases</a>) - [Commits](<a href="https://github.com/ipfs/go-cid/compare/v0.0.2...v0.0.3" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/compare/v0.0.2...v0.0.3</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/5e9369661f3393ed310da5731269c8c11ee6e22e Merge pull request #14 from ipfs/dependabot/go_modules/github.com/ipfs/go-cid... 2019-09-24T16:48:25-07:00 Steven Allen steven@stebalien.com Bump github.com/ipfs/go-cid from 0.0.2 to 0.0.3 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/15139bec0a46bf1b80d53eaa8e01fce8987a9478 Bump github.com/multiformats/go-multihash from 0.0.8 to 0.0.9 2019-11-18T11:23:45+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/multiformats/go-multihash](<a href="https://github.com/multiformats/go-multihash" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash</a>) from 0.0.8 to 0.0.9. - [Release notes](<a href="https://github.com/multiformats/go-multihash/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/releases</a>) - [Commits](<a href="https://github.com/multiformats/go-multihash/compare/v0.0.8...v0.0.9" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/compare/v0.0.8...v0.0.9</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/b74a6a548d3a95a90efb2f64e8611783decf7535 Merge pull request #17 from ipfs/dependabot/go_modules/github.com/multiformat... 2019-11-18T07:50:20-06:00 Steven Allen steven@stebalien.com Bump github.com/multiformats/go-multihash from 0.0.8 to 0.0.9 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/3c9b043fa2f3c96da850f128033f6e4a4160bfe3 Bump github.com/multiformats/go-multihash from 0.0.9 to 0.0.10 2019-12-09T11:20:44+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/multiformats/go-multihash](<a href="https://github.com/multiformats/go-multihash" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash</a>) from 0.0.9 to 0.0.10. - [Release notes](<a href="https://github.com/multiformats/go-multihash/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/releases</a>) - [Commits](<a href="https://github.com/multiformats/go-multihash/compare/v0.0.9...v0.0.10" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/compare/v0.0.9...v0.0.10</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/492a89d852fd8e36cadab6a5c1dd82c11557d94e Merge pull request #18 from ipfs/dependabot/go_modules/github.com/multiformat... 2019-12-09T06:21:56-06:00 Steven Allen steven@stebalien.com Bump github.com/multiformats/go-multihash from 0.0.9 to 0.0.10 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/2186d089d0517f44e3164ccc5029f11da313639f Bump github.com/ipfs/go-cid from 0.0.3 to 0.0.4 2019-12-16T11:21:49+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/ipfs/go-cid](<a href="https://github.com/ipfs/go-cid" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid</a>) from 0.0.3 to 0.0.4. - [Release notes](<a href="https://github.com/ipfs/go-cid/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/releases</a>) - [Commits](<a href="https://github.com/ipfs/go-cid/compare/v0.0.3...v0.0.4" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/compare/v0.0.3...v0.0.4</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/32e8cc87545d767f35b8726f14c52a9601b72386 Merge pull request #19 from ipfs/dependabot/go_modules/github.com/ipfs/go-cid... 2019-12-18T12:41:01+01:00 Steven Allen steven@stebalien.com Bump github.com/ipfs/go-cid from 0.0.3 to 0.0.4 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/37ce1aa4f4122170c2138d131f5599ed122e96ac Bump github.com/multiformats/go-multihash from 0.0.10 to 0.0.13 2020-02-10T11:22:33+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/multiformats/go-multihash](<a href="https://github.com/multiformats/go-multihash" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash</a>) from 0.0.10 to 0.0.13. - [Release notes](<a href="https://github.com/multiformats/go-multihash/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/releases</a>) - [Commits](<a href="https://github.com/multiformats/go-multihash/compare/v0.0.10...v0.0.13" rel="nofollow noreferrer noopener" target="_blank">https://github.com/multiformats/go-multihash/compare/v0.0.10...v0.0.13</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/fc997fb9f5a594f6467e707f27a761cc54acbf31 Merge pull request #20 from ipfs/dependabot/go_modules/github.com/multiformat... 2020-02-10T07:32:49-08:00 Steven Allen steven@stebalien.com Bump github.com/multiformats/go-multihash from 0.0.10 to 0.0.13 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/5323895d0cb5d8169ef1ea80fafbd456721d07e4 Bump github.com/ipfs/go-cid from 0.0.4 to 0.0.5 2020-02-10T15:34:04+00:00 dependabot-preview[bot] 27856297+dependabot-preview[bot]@users.noreply.github.com Bumps [github.com/ipfs/go-cid](<a href="https://github.com/ipfs/go-cid" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid</a>) from 0.0.4 to 0.0.5. - [Release notes](<a href="https://github.com/ipfs/go-cid/releases" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/releases</a>) - [Commits](<a href="https://github.com/ipfs/go-cid/compare/v0.0.4...v0.0.5" rel="nofollow noreferrer noopener" target="_blank">https://github.com/ipfs/go-cid/compare/v0.0.4...v0.0.5</a>) Signed-off-by: <span data-trailer="Signed-off-by:"><a href="mailto:support@dependabot.com" title="support@dependabot.com"><img alt="default avatar" src="https://secure.gravatar.com/avatar/c37982ef5d343cc3b27d3e5ecf6d6ed5?s=32&amp;d=identicon" class="avatar s16 avatar-inline"></a><a href="mailto:support@dependabot.com" title="support@dependabot.com">dependabot-preview[bot]</a> &lt;<a href="mailto:support@dependabot.com" title="support@dependabot.com">support@dependabot.com</a>&gt;</span> https://gitlab.dms3.io/dms3/go-cidutil/-/commit/d9f589d1d403ebba739a63965e497bbaf06f62cd Merge pull request #21 from ipfs/dependabot/go_modules/github.com/ipfs/go-cid... 2020-02-10T12:29:20-08:00 Steven Allen steven@stebalien.com Bump github.com/ipfs/go-cid from 0.0.4 to 0.0.5 https://gitlab.dms3.io/dms3/go-cidutil/-/commit/dbe4543c148ca83225b2916bd28d11602d779056 Add standard issue template 2020-04-27T11:37:58+02:00 Hector Sanjuan code@hector.link https://gitlab.dms3.io/dms3/go-cidutil/-/commit/2a0f04ff781b4a31abe7fc2c5e23a62e92a319cc Add autocomment configuration 2020-05-04T12:16:28+02:00 Hector Sanjuan code@hector.link https://gitlab.dms3.io/dms3/go-cidutil/-/commit/b76d50bc63b64be8605a085a0ac8399069d1bedd add license file so it can be found by go-licenses 2021-02-10T23:25:21-05:00 Nicholas Bollweg nick.bollweg@gmail.com https://gitlab.dms3.io/dms3/go-cidutil/-/commit/74e39ea04da2ff5b1c05693db941513d5b666cc1 Merge pull request #27 from bollwyvl/patch-1 2021-02-10T21:13:19-08:00 Will will.scott@protocol.ai add license file so it can be found by go-licenses https://gitlab.dms3.io/dms3/go-cidutil/-/commit/87c6429dee15afb592deaed69549e335a6851751 Merge remote-tracking branch 'upstream/master' into reference 2021-05-02T12:04:16-04:00 tavit ohanian tavit@dms3.io https://gitlab.dms3.io/dms3/go-cidutil/-/commit/21dc95729d3c3fa5af09375f9463ee36ec5897a7 initial port 2021-05-24T05:18:31-04:00 tavit ohanian tavit@dms3.io https://gitlab.dms3.io/dms3/go-cidutil/-/commit/1297a9f74e77eb0b010a1c7251319241ac1c7428 Merge branch 'port-2021-05-02' into 'master' 2021-05-24T09:23:16+00:00 tavit ohanian tavit@dms3.io Port 2021 05 02 See merge request dms3/public/go-cidutil!1
blank_issues_enabled: false
contact_links:
- name: Getting Help on IPFS
url: https://ipfs.io/help
about: All information about how and where to get help on IPFS.
- name: IPFS Official Forum
url: https://discuss.ipfs.io
about: Please post general questions, support requests, and discussions here.
---
name: Open an issue
about: Only for actionable issues relevant to this repository.
title: ''
labels: need/triage
assignees: ''
---
<!--
Hello! To ensure this issue is correctly addressed as soon as possible by the IPFS team, please try to make sure:
- This issue is relevant to this repository's topic or codebase.
- A clear description is provided. It should includes as much relevant information as possible and clear scope for the issue to be actionable.
FOR GENERAL DISCUSSION, HELP OR QUESTIONS, please see the options at https://ipfs.io/help or head directly to https://discuss.ipfs.io.
(you can delete this section after reading)
-->
# Configuration for welcome - https://github.com/behaviorbot/welcome
# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
# Comment to be posted to on first time issues
newIssueWelcomeComment: >
Thank you for submitting your first issue to this repository! A maintainer
will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the
necessary information to make this process easy! Any information that can
help save additional round trips is useful! We currently aim to give
initial feedback within **two business days**. If this does not happen, feel
free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an
overview of priorities, assignments and additional actions requested by the
maintainers:
- "Priority" labels will show how urgent this is for the team.
- "Status" labels will show if this is ready to be worked on, blocked, or in progress.
- "Need" labels will indicate if additional input or analysis is required.
Finally, remember to use https://discuss.ipfs.io if you just need general
support.
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
# Comment to be posted to on PRs from first time contributors in your repository
newPRWelcomeComment: >
Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure
that:
* The context for this PR is clear, with relevant discussion, decisions
and stakeholders linked/mentioned.
* Your contribution itself is clear (code comments, self-review for the
rest) and in its best form. Follow the [code contribution
guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#code-contribution-guidelines)
if they apply.
Getting other community members to do a review would be great help too on
complex PRs (you can ask in the chats/forums). If you are unsure about
something, just leave us a comment.
Next steps:
* A maintainer will triage and assign priority to this PR, commenting on
any missing things and potentially assigning a reviewer for high
priority items.
* The PR gets reviews, discussed and approvals as needed.
* The PR is merged by maintainers when it has been approved and comments addressed.
We currently aim to provide initial feedback/triaging within **two business
days**. Please keep an eye on any labelling actions, as these will indicate
priorities and status of your contribution.
We are very grateful for your contribution!
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
# Comment to be posted to on pull requests merged by a first time user
# Currently disabled
#firstPRMergeComment: ""
stages:
- build
- test
variables:
BUILD_DIR: "/tmp/$CI_CONCURRENT_PROJECT_ID"
before_script:
- mkdir -p $BUILD_DIR/src
- cd $BUILD_DIR/src
- if [ -d $CI_PROJECT_DIR ]
- then
- echo "soft link $CI_PROJECT_DIR exists"
- else
- echo "creating soft link $CI_PROJECT_DIR"
- ln -s $CI_PROJECT_DIR
- fi
- cd $CI_PROJECT_DIR
build:
stage: build
tags:
- testing
script:
- echo $CI_JOB_STAGE
- go build
test:
stage: test
tags:
- testing
script:
- echo $CI_JOB_STAGE
- go test -cover
coverage: '/coverage: \d+.\d+% of statements/'
0.2.1: Qmf3gRH2L1QZy92gJHJEwKmBJKJGVf8RpN2kPPD2NQWg8G
os:
- linux
language: go
go:
- 1.11.x
env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gomod
# disable travis install
install:
- true
script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
cache:
directories:
- $GOPATH/pkg/mod
- $HOME/.cache/go-build
notifications:
email: false
The MIT License (MIT)
Copyright (c) Protocol Labs, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# go-cidutil # go-cidutil
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![GoDoc](https://godoc.org/github.com/ipfs/go-ipfs-cidutil?status.svg)](https://godoc.org/github.com/ipfs/go-ipfs-cidutil)
[![Build Status](https://travis-ci.org/ipfs/go-ipfs-cidutil.svg?branch=master)](https://travis-ci.org/ipfs/go-ipfs-cidutil)
> go-cidutil implements various utilities and helper functions for working with CIDs
## Lead Maintainer
[Steven Allen](https://github.com/Stebalien)
## Contribute
PRs accepted.
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
MIT © Protocol Labs, Inc.
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
cidutil "gitlab.dms3.io/dms3/public/go-cidutil"
mb "github.com/multiformats/go-multibase"
c "gitlab.dms3.io/dms3/public/go-cid"
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: %s [-b multibase-code] [-v cid-version] [--filter] <fmt-str> <cid> ...\n", os.Args[0])
fmt.Fprintf(os.Stderr, "--filter will read from stdin and convert anything that looks like a <cid>\n")
fmt.Fprintf(os.Stderr, " -- including any non-cids that are valid Multihashes).\n")
fmt.Fprintf(os.Stderr, "<fmt-str> is either 'prefix' or a printf style format string:\n%s", cidutil.FormatRef)
os.Exit(2)
}
func main() {
if len(os.Args) < 2 {
usage()
}
newBase := mb.Encoding(-1)
var verConv func(cid c.Cid) (c.Cid, error)
args := os.Args[1:]
filter := false
outer:
for len(args) > 0 {
switch args[0] {
case "-b":
if len(args) < 2 {
usage()
}
encoder, err := mb.EncoderByName(args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
os.Exit(2)
}
newBase = encoder.Encoding()
args = args[2:]
case "-v":
if len(args) < 2 {
usage()
}
switch args[1] {
case "0":
verConv = toCidV0
case "1":
verConv = toCidV1
default:
fmt.Fprintf(os.Stderr, "Error: Invalid cid version: %s\n", args[1])
os.Exit(2)
}
args = args[2:]
case "--filter":
filter = true
args = args[1:]
default:
break outer
}
}
if len(args) < 1 {
usage()
}
fmtStr := args[0]
switch fmtStr {
case "prefix":
fmtStr = "%P"
default:
if strings.IndexByte(fmtStr, '%') == -1 {
fmt.Fprintf(os.Stderr, "Error: Invalid format string: %s\n", fmtStr)
os.Exit(2)
}
}
format := func(cid c.Cid, cidStr string) (string, error) {
base := newBase
if base == -1 {
base, _ = c.ExtractEncoding(cidStr)
}
var err error
if verConv != nil {
cid, err = verConv(cid)
if err != nil {
return "", err
}
}
return cidutil.Format(fmtStr, base, cid)
}
if filter {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
buf := scanner.Bytes()
for {
i, j, cid, cidStr := cidutil.ScanForCid(buf)
os.Stdout.Write(buf[0:i])
if i == len(buf) {
os.Stdout.Write([]byte{'\n'})
break
}
str, err := format(cid, cidStr)
switch err.(type) {
case cidutil.FormatStringError:
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(2)
default:
// just use the orignal sting on non-fatal error
str = cidStr
case nil:
}
io.WriteString(os.Stdout, str)
buf = buf[j:]
}
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(2)
}
} else {
for _, cidStr := range args[1:] {
cid, err := c.Decode(cidStr)
if err != nil {
fmt.Fprintf(os.Stdout, "!INVALID_CID!\n")
errorMsg("%s: %v", cidStr, err)
// Don't abort on a bad cid
continue
}
str, err := format(cid, cidStr)
switch err.(type) {
case cidutil.FormatStringError:
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(2)
default:
fmt.Fprintf(os.Stdout, "!ERROR!\n")
errorMsg("%s: %v", cidStr, err)
// Don't abort on cid specific errors
continue
case nil:
// no error
}
fmt.Fprintf(os.Stdout, "%s\n", str)
}
}
os.Exit(exitCode)
}
var exitCode = 0
func errorMsg(fmtStr string, a ...interface{}) {
fmt.Fprintf(os.Stderr, "Error: ")
fmt.Fprintf(os.Stderr, fmtStr, a...)
fmt.Fprintf(os.Stderr, "\n")
exitCode = 1
}
func toCidV0(cid c.Cid) (c.Cid, error) {
if cid.Type() != c.DagProtobuf {
return c.Cid{}, fmt.Errorf("can't convert non-protobuf nodes to cidv0")
}
return c.NewCidV0(cid.Hash()), nil
}
func toCidV1(cid c.Cid) (c.Cid, error) {
return c.NewCidV1(cid.Type(), cid.Hash()), nil
}
package main
import (
"fmt"
"testing"
c "gitlab.dms3.io/dms3/public/go-cid"
)
func TestCidConv(t *testing.T) {
cidv0 := "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
cidv1 := "bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354"
cid, err := c.Decode(cidv0)
if err != nil {
t.Fatal(err)
}
cid, err = toCidV1(cid)
if err != nil {
t.Fatal(err)
}
if cid.String() != cidv1 {
t.Fatalf("conversion failure: %s != %s", cid, cidv1)
}
cid, err = toCidV0(cid)
if err != nil {
t.Fatal(err)
}
cidStr := cid.String()
if cidStr != cidv0 {
t.Error(fmt.Sprintf("conversion failure, expected: %s; but got: %s", cidv0, cidStr))
}
}
func TestBadCidConv(t *testing.T) {
// this cid is a raw leaf and should not be able to convert to cidv0
cidv1 := "bafkreifit7vvfkf2cwwzvyycdczm5znbdbqx54ab6shbesvwgkwthdf77y"
cid, err := c.Decode(cidv1)
if err != nil {
t.Fatal(err)
}
cid, err = toCidV0(cid)
if err == nil {
t.Fatal("expected failure")
}
}
package cidenc
import (
cid "github.com/ipfs/go-cid"
mbase "github.com/multiformats/go-multibase"
)
// Encoder is a basic Encoder that will encode CIDs using a specified
// base and optionally upgrade a CIDv0 to CIDv1
type Encoder struct {
Base mbase.Encoder // The multibase to use
Upgrade bool // If true upgrade CIDv0 to CIDv1 when encoding
}
// Default return a new default encoder
func Default() Encoder {
return Encoder{Base: mbase.MustNewEncoder(mbase.Base32)}
}
// Encode encodes the cid using the parameters of the Encoder
func (enc Encoder) Encode(c cid.Cid) string {
if enc.Upgrade && c.Version() == 0 {
c = cid.NewCidV1(c.Type(), c.Hash())
}
return c.Encode(enc.Base)
}
// Recode reencodes the cid string to match the parameters of the
// encoder
func (enc Encoder) Recode(v string) (string, error) {
skip, err := enc.noopRecode(v)
if skip || err != nil {
return v, err
}
c, err := cid.Decode(v)
if err != nil {
return v, err
}
return enc.Encode(c), nil
}
func (enc Encoder) noopRecode(v string) (bool, error) {
if len(v) < 2 {
return false, cid.ErrCidTooShort
}
ver := cidVer(v)
skip := ver == 0 && !enc.Upgrade || ver == 1 && v[0] == byte(enc.Base.Encoding())
return skip, nil
}
func cidVer(v string) int {
if len(v) == 46 && v[:2] == "Qm" {
return 0
} else {
return 1
}
}
package cidenc
import (
"testing"
cid "github.com/ipfs/go-cid"
mbase "github.com/multiformats/go-multibase"
)
func TestCidEncoder(t *testing.T) {
cidv0str := "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
cidv1str := "zdj7Wkkhxcu2rsiN6GUyHCLsSLL47kdUNfjbFqBUUhMFTZKBi"
cidb32str := "bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku"
cidv0, _ := cid.Decode(cidv0str)
cidv1, _ := cid.Decode(cidv1str)
testEncode := func(enc Encoder, cid cid.Cid, expect string) {
actual := enc.Encode(cid)
if actual != expect {
t.Errorf("%+v.Encode(%s): expected %s but got %s", enc, cid, expect, actual)
}
}
testRecode := func(enc Encoder, cid string, expect string) {
actual, err := enc.Recode(cid)
if err != nil {
t.Errorf("%+v.Recode(%s): %s", enc, cid, err)
return
}
if actual != expect {
t.Errorf("%+v.Recode(%s): expected %s but got %s", enc, cid, expect, actual)
}
}
enc := Encoder{Base: mbase.MustNewEncoder(mbase.Base58BTC), Upgrade: false}
testEncode(enc, cidv0, cidv0str)
testEncode(enc, cidv1, cidv1str)
testRecode(enc, cidv0str, cidv0str)
testRecode(enc, cidv1str, cidv1str)
testRecode(enc, cidb32str, cidv1str)
enc = Encoder{Base: mbase.MustNewEncoder(mbase.Base58BTC), Upgrade: true}
testEncode(enc, cidv0, cidv1str)
testEncode(enc, cidv1, cidv1str)
testRecode(enc, cidv0str, cidv1str)
testRecode(enc, cidv1str, cidv1str)
testRecode(enc, cidb32str, cidv1str)
enc = Encoder{Base: mbase.MustNewEncoder(mbase.Base32), Upgrade: false}
testEncode(enc, cidv0, cidv0str)
testEncode(enc, cidv1, cidb32str)
testRecode(enc, cidv0str, cidv0str)
testRecode(enc, cidv1str, cidb32str)
testRecode(enc, cidb32str, cidb32str)
enc = Encoder{Base: mbase.MustNewEncoder(mbase.Base32), Upgrade: true}
testEncode(enc, cidv0, cidb32str)
testEncode(enc, cidv1, cidb32str)
testRecode(enc, cidv0str, cidb32str)
testRecode(enc, cidv1str, cidb32str)
testRecode(enc, cidb32str, cidb32str)
enc = Default()
testEncode(enc, cidv0, cidv0str)
testEncode(enc, cidv1, cidb32str)
testRecode(enc, cidv0str, cidv0str)
testRecode(enc, cidv1str, cidb32str)
testRecode(enc, cidb32str, cidb32str)
}
coverage:
range: "50...100"
comment: off
package cidutil
import (
"bytes"
"fmt"
mb "github.com/multiformats/go-multibase"
mh "github.com/multiformats/go-multihash"
c "gitlab.dms3.io/dms3/public/go-cid"
)
// FormatRef is a string documenting the format string for the Format function
const FormatRef = `
%% literal %
%b multibase name
%B multibase code
%v version string
%V version number
%c codec name
%C codec code
%h multihash name
%H multihash code
%L hash digest length
%m multihash encoded in base %b (with multibase prefix)
%M multihash encoded in base %b without multibase prefix
%d hash digest encoded in base %b (with multibase prefix)
%D hash digest encoded in base %b without multibase prefix
%s cid string encoded in base %b (1)
%S cid string encoded in base %b without multibase prefix
%P cid prefix: %v-%c-%h-%L
(1) For CID version 0 the multibase must be base58btc and no prefix is
used. For Cid version 1 the multibase prefix is included.
`
// Format formats a cid according to the format specificer as
// documented in the FormatRef constant
func Format(fmtStr string, base mb.Encoding, cid c.Cid) (string, error) {
p := cid.Prefix()
var out bytes.Buffer
var err error
encoder, err := mb.NewEncoder(base)
if err != nil {
return "", err
}
for i := 0; i < len(fmtStr); i++ {
if fmtStr[i] != '%' {
out.WriteByte(fmtStr[i])
continue
}
i++
if i >= len(fmtStr) {
return "", FormatStringError{"premature end of format string", ""}
}
switch fmtStr[i] {
case '%':
out.WriteByte('%')
case 'b': // base name
out.WriteString(baseToString(base))
case 'B': // base code
out.WriteByte(byte(base))
case 'v': // version string
fmt.Fprintf(&out, "cidv%d", p.Version)
case 'V': // version num
fmt.Fprintf(&out, "%d", p.Version)
case 'c': // codec name
out.WriteString(codecToString(p.Codec))
case 'C': // codec code
fmt.Fprintf(&out, "%d", p.Codec)
case 'h': // hash fun name
out.WriteString(hashToString(p.MhType))
case 'H': // hash fun code
fmt.Fprintf(&out, "%d", p.MhType)
case 'L': // hash length
fmt.Fprintf(&out, "%d", p.MhLength)
case 'm', 'M': // multihash encoded in base %b
out.WriteString(encode(encoder, cid.Hash(), fmtStr[i] == 'M'))
case 'd', 'D': // hash digest encoded in base %b
dec, err := mh.Decode(cid.Hash())
if err != nil {
return "", err
}
out.WriteString(encode(encoder, dec.Digest, fmtStr[i] == 'D'))
case 's': // cid string encoded in base %b
str, err := cid.StringOfBase(base)
if err != nil {
return "", err
}
out.WriteString(str)
case 'S': // cid string without base prefix
out.WriteString(encode(encoder, cid.Bytes(), true))
case 'P': // prefix
fmt.Fprintf(&out, "cidv%d-%s-%s-%d",
p.Version,
codecToString(p.Codec),
hashToString(p.MhType),
p.MhLength,
)
default:
return "", FormatStringError{"unrecognized specifier in format string", fmtStr[i-1 : i+1]}
}
}
return out.String(), err
}
// FormatStringError is the error return from Format when the format
// string is ill formed
type FormatStringError struct {
Message string
Specifier string
}
func (e FormatStringError) Error() string {
if e.Specifier == "" {
return e.Message
} else {
return fmt.Sprintf("%s: %s", e.Message, e.Specifier)
}
}
func baseToString(base mb.Encoding) string {
baseStr, ok := mb.EncodingToStr[base]
if !ok {
return fmt.Sprintf("base?%c", base)
}
return baseStr
}
func codecToString(num uint64) string {
name, ok := c.CodecToStr[num]
if !ok {
return fmt.Sprintf("codec?%d", num)
}
return name
}
func hashToString(num uint64) string {
name, ok := mh.Codes[num]
if !ok {
return fmt.Sprintf("hash?%d", num)
}
return name
}
func encode(base mb.Encoder, data []byte, strip bool) string {
str := base.Encode(data)
if strip {
return str[1:]
}
return str
}
// ScanForCid scans bytes for anything resembling a CID. If one is
// found `i` will point to the begging of the cid and `j` to to the
// end and the cid will be returned, otherwise `i` and `j` will point
// the end of the buffer and the cid will be `Undef`.
func ScanForCid(buf []byte) (i, j int, cid c.Cid, cidStr string) {
i = 0
for {
i = j
for i < len(buf) && !asciiIsAlpha(buf[i]) {
i++
}
j = i
if i == len(buf) {
return
}
for j < len(buf) && asciiIsAlpha(buf[j]) {
j++
}
if j-i <= 1 || j-i > 128 || !supported[buf[i]] {
continue
}
var err error
cidStr = string(buf[i:j])
cid, err = c.Decode(cidStr)
if err == nil {
return
}
}
}
var supported = make([]bool, 256)
func init() {
// for now base64 encoding are not supported as they contain non
// alhphanumeric characters
supportedPrefixes := []byte("QfFbBcCvVtThzZ")
for _, b := range supportedPrefixes {
supported[b] = true
}
}
func asciiIsAlpha(b byte) bool {
return ('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') || ('0' <= b && b <= '9')
}
package cidutil
import (
"fmt"
"testing"
mb "github.com/multiformats/go-multibase"
c "gitlab.dms3.io/dms3/public/go-cid"
)
func TestFmt(t *testing.T) {
cids := map[string]string{
"cidv0": "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn",
"cidv1": "zdj7WfLr9DhLrb1hsoSi4fSdjjxuZmeqgEtBPWxMLtPbDNbFD",
}
tests := []struct {
cidId string
newBase mb.Encoding
fmtStr string
result string
}{
{"cidv0", -1, "%P", "cidv0-protobuf-sha2-256-32"},
{"cidv0", -1, "%b-%v-%c-%h-%L", "base58btc-cidv0-protobuf-sha2-256-32"},
{"cidv0", -1, "%s", "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"},
{"cidv0", -1, "%S", "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"},
{"cidv0", -1, "ver#%V/#%C/#%H/%L", "ver#0/#112/#18/32"},
{"cidv0", -1, "%m", "zQmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"},
{"cidv0", -1, "%M", "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"},
{"cidv0", -1, "%d", "z72gdmFAgRzYHkJzKiL8MgMMRW3BTSCGyDHroPxJbxMJn"},
{"cidv0", -1, "%D", "72gdmFAgRzYHkJzKiL8MgMMRW3BTSCGyDHroPxJbxMJn"},
{"cidv0", 'B', "%S", "CIQFTFEEHEDF6KLBT32BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y"},
{"cidv0", 'B', "%B%S", "BCIQFTFEEHEDF6KLBT32BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y"},
{"cidv1", -1, "%P", "cidv1-protobuf-sha2-256-32"},
{"cidv1", -1, "%b-%v-%c-%h-%L", "base58btc-cidv1-protobuf-sha2-256-32"},
{"cidv1", -1, "%s", "zdj7WfLr9DhLrb1hsoSi4fSdjjxuZmeqgEtBPWxMLtPbDNbFD"},
{"cidv1", -1, "%S", "dj7WfLr9DhLrb1hsoSi4fSdjjxuZmeqgEtBPWxMLtPbDNbFD"},
{"cidv1", -1, "ver#%V/#%C/#%H/%L", "ver#1/#112/#18/32"},
{"cidv1", -1, "%m", "zQmYFbmndVP7QqAVWyKhpmMuQHMaD88pkK57RgYVimmoh5H"},
{"cidv1", -1, "%M", "QmYFbmndVP7QqAVWyKhpmMuQHMaD88pkK57RgYVimmoh5H"},
{"cidv1", -1, "%d", "zAux4gVVsLRMXtsZ9fd3tFEZN4jGYB6kP37fgoZNTc11H"},
{"cidv1", -1, "%D", "Aux4gVVsLRMXtsZ9fd3tFEZN4jGYB6kP37fgoZNTc11H"},
{"cidv1", 'B', "%s", "BAFYBEIETJGSRL3EQPQPCABV3G6IUBYTSIFVQ24XRRHD3JUETSKLTGQ7DJA"},
{"cidv1", 'B', "%S", "AFYBEIETJGSRL3EQPQPCABV3G6IUBYTSIFVQ24XRRHD3JUETSKLTGQ7DJA"},
{"cidv1", 'B', "%B%S", "BAFYBEIETJGSRL3EQPQPCABV3G6IUBYTSIFVQ24XRRHD3JUETSKLTGQ7DJA"},
}
for _, tc := range tests {
name := fmt.Sprintf("%s/%s", tc.cidId, tc.fmtStr)
if tc.newBase != -1 {
name = fmt.Sprintf("%s/%c", name, tc.newBase)
}
cidStr := cids[tc.cidId]
t.Run(name, func(t *testing.T) {
testFmt(t, cidStr, tc.newBase, tc.fmtStr, tc.result)
})
}
}
func testFmt(t *testing.T, cidStr string, newBase mb.Encoding, fmtStr string, result string) {
cid, err := c.Decode(cidStr)
if err != nil {
t.Fatal(err)
}
base := newBase
if newBase == -1 {
base, _ = c.ExtractEncoding(cidStr)
}
str, err := Format(fmtStr, base, cid)
if err != nil {
t.Fatal(err)
}
if str != result {
t.Error(fmt.Sprintf("expected: %s; but got: %s", result, str))
}
}
func TestScanForCid(t *testing.T) {
testStr := []byte(`
/ipfs/QmYFbmndVP7QqAVWyKhpmMuQHMaD88pkK57RgYVimmoh5H 22 45
/ipfs/zdj7WfLr9DhLrb1hsoSi4fSdjjxuZmeqgEtBPWxMLtPbDNbFD/foobar
BAFYBEIETJGSRL3EQPQPCABV3G6IUBYTSIFVQ24XRRHD3JUETSKLTGQ7DJA
skip me (too long): QmYFbmndVP7QqAVWyKhpmMuQHMaD88pkK57RgYVimmoh5H876
skip me (too short): bafybeietjgsrl3eqpqpcabv3g6iubytsifvq
bafybeietjgsrl3eqpqpcabv3g6iubytsifvq24xrrhd3juetskltgq7dja
bafybeietjgsrl3eqpqpcabv3g6iubytsifvq24xrrhd3juetskltgq7dja.
`)
cids := []string{
"QmYFbmndVP7QqAVWyKhpmMuQHMaD88pkK57RgYVimmoh5H",
"zdj7WfLr9DhLrb1hsoSi4fSdjjxuZmeqgEtBPWxMLtPbDNbFD",
"BAFYBEIETJGSRL3EQPQPCABV3G6IUBYTSIFVQ24XRRHD3JUETSKLTGQ7DJA",
"bafybeietjgsrl3eqpqpcabv3g6iubytsifvq24xrrhd3juetskltgq7dja",
"bafybeietjgsrl3eqpqpcabv3g6iubytsifvq24xrrhd3juetskltgq7dja",
}
buf := testStr
idx := 0
offset := 0
for len(buf) > 0 {
_, j, _, cidStr := ScanForCid(buf)
if cidStr != "" && cids[idx] != cidStr {
t.Fatalf("Scan failed, expected %s, got %s (idx=%d offset=%d)", cids[idx], cidStr, idx, offset)
}
buf = buf[j:]
offset += j
idx++
}
}
github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc=
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/ipfs/go-cid v0.0.2 h1:tuuKaZPU1M6HcejsO3AcYWW8sZ8MTvyxfc4uqB4eFE8=
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid v0.0.3 h1:UIAh32wymBpStoe83YCzwVQQ5Oy/H0FdxvUS6DJDzms=
github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-cid v0.0.4 h1:UlfXKrZx1DjZoBhQHmNHLC1fK1dUJDN20Y28A7s+gJ8=
github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M=
github.com/ipfs/go-cid v0.0.5 h1:o0Ix8e/ql7Zb5UVUJEUfjsWCIY8t48++9lR8qi6oiJU=
github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog=
github.com/ipfs/go-cid v0.0.7 h1:ysQJVJA3fNDF1qigJbsSQOdjhVLsOEoPdh0+R97k3jY=
github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78=
github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA=
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.9 h1:aoijQXYYl7Xtb2pUUP68R+ys1TlnlR3eX6wmozr0Hp4=
github.com/multiformats/go-multihash v0.0.9/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.10 h1:lMoNbh2Ssd9PUF74Nz008KGzGPlfeV6wH3rit5IIGCM=
github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13 h1:06x+mk/zj1FoMsgNejLpy6QTvJqlSt/BhLEy87zidlc=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-varint v0.0.5 h1:XVZwSo04Cs3j/jS0uAEPpT3JY6DzMcVLLoWOSnCxOjg=
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
gitlab.dms3.io/dms3/public/go-cid v0.0.0 h1:DKvGTYv5GqSEeVLfQAHBbsFZuWCZFNK5BHdBFykF45E=
gitlab.dms3.io/dms3/public/go-cid v0.0.0/go.mod h1:3WDixn/g/St71Wop8EY5QsPF3IHBOxb4VIgwWeOl5BQ=
gitlab.dms3.io/dms3/public/go-cid v0.0.1 h1:qs4dtkDigcLGY/58dIZaFjKLt+orrTcmTBvtqaM3570=
gitlab.dms3.io/dms3/public/go-cid v0.0.1/go.mod h1:GQw3gc4CSrFY+aX6M+OBQDlg0p5/eQJoRrayaZzkAOQ=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
package cidutil
import (
mhash "github.com/multiformats/go-multihash"
cid "gitlab.dms3.io/dms3/public/go-cid"
)
// InlineBuilder is a cid.Builder that will use the id multihash when the
// size of the content is no more than limit
type InlineBuilder struct {
cid.Builder // Parent Builder
Limit int // Limit (inclusive)
}
// WithCodec implements the cid.Builder interface
func (p InlineBuilder) WithCodec(c uint64) cid.Builder {
return InlineBuilder{p.Builder.WithCodec(c), p.Limit}
}
// Sum implements the cid.Builder interface
func (p InlineBuilder) Sum(data []byte) (cid.Cid, error) {
if len(data) > p.Limit {
return p.Builder.Sum(data)
}
return cid.V1Builder{Codec: p.GetCodec(), MhType: mhash.ID}.Sum(data)
}
package cidutil
import (
"math/rand"
"testing"
mhash "github.com/multiformats/go-multihash"
cid "gitlab.dms3.io/dms3/public/go-cid"
)
func TestInlineBuilderSmallValue(t *testing.T) {
builder := InlineBuilder{cid.V0Builder{}, 64}
c, err := builder.Sum([]byte("Hello World"))
if err != nil {
t.Fatal(err)
}
if c.Prefix().MhType != mhash.ID {
t.Fatal("Inliner builder failed to use ID Multihash on small values")
}
}
func TestInlinerBuilderLargeValue(t *testing.T) {
builder := InlineBuilder{cid.V0Builder{}, 64}
data := make([]byte, 512)
rand.Read(data)
c, err := builder.Sum(data)
if err != nil {
t.Fatal(err)
}
if c.Prefix().MhType == mhash.ID {
t.Fatal("Inliner builder used ID Multihash on large values")
}
}
package cidutil
import (
"context"
c "gitlab.dms3.io/dms3/public/go-cid"
)
type Set = c.Set
func NewSet() *Set { return c.NewSet() }
// StreamingSet is an extension of Set which allows to implement back-pressure
// for the Visit function
type StreamingSet struct {
Set *Set
New chan c.Cid
}
// NewStreamingSet initializes and returns new Set.
func NewStreamingSet() *StreamingSet {
return &StreamingSet{
Set: c.NewSet(),
New: make(chan c.Cid),
}
}
// Visitor creates new visitor which adds a Cids to the set and emits them to
// the set.New channel
func (s *StreamingSet) Visitor(ctx context.Context) func(c c.Cid) bool {
return func(c c.Cid) bool {
if s.Set.Visit(c) {
select {
case s.New <- c:
case <-ctx.Done():
}
return true
}
return false
}
}
package cidutil
import (
"sort"
"gitlab.dms3.io/dms3/public/go-cid"
)
// Slice is a convenience type for sorting CIDs
type Slice []cid.Cid
func (s Slice) Len() int {
return len(s)
}
func (s Slice) Less(i, j int) bool {
return s[i].KeyString() < s[j].KeyString()
}
func (s Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s Slice) Sort() {
sort.Sort(s)
}
// Sort sorts a slice of CIDs
func Sort(s []cid.Cid) {
Slice(s).Sort()
}