Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pipe multiple newline delimited CIDs #8

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

alanshaw
Copy link
Member

Allows the user to pipe a file of newline delimited CIDs to the base32 or format command instead of invoking it for each or passing them all as parameters.

The motivation for this originally was to fix an issue where the following command throws an error because the input has a trailing newline:

$ jsipfs id | json id | jsipfs cid base32
bafybeidta3hkxk3ihxfsk765oswgsjhmvcnkeestyuov6r2t5tyts4xuoe
Error: invalid cid: 
    at Object.base32 (/Users/alan/.iim/dists/[email protected]/node_modules/cid-tool/src/core/base32.js:10:11)
  Error: multihash too short. must be > 3 bytes.
    at Function.validateCID (/Users/alan/.iim/dists/[email protected]/node_modules/cids/src/index.js:286:13)
    at new CID (/Users/alan/.iim/dists/[email protected]/node_modules/cids/src/index.js:91:11)
    at new CID (/Users/alan/.iim/dists/[email protected]/node_modules/class-is/index.js:15:17)
    at Object.base32 (/Users/alan/.iim/dists/[email protected]/node_modules/cid-tool/src/core/base32.js:8:11)
    at Socket.<anonymous> (/Users/alan/.iim/dists/[email protected]/node_modules/cid-tool/src/cli/commands/base32.js:17:27)
    at Socket.emit (events.js:210:5)
    at addChunk (_stream_readable.js:326:12)
    at readableAddChunk (_stream_readable.js:301:11)
    at Socket.Readable.push (_stream_readable.js:235:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:182:23)

Newline delimited data (like ndjson for example) usually ignores a trailing newline so we do the same here, fixing the error but allowing us to easily support multiple CIDs being piped.

I want to add this command in an example for the js-ipfs 0.40 release to show how people could convert their Peer ID to a base32 CID for use in IPNS paths.

@alanshaw alanshaw merged commit 0ea16fa into master Nov 25, 2019
@alanshaw alanshaw deleted the feat/support-pipe-multiple-nd-cids branch November 25, 2019 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants