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

go-ipfs-cmds can support passing stateful encoders #5780

Open
hannahhoward opened this issue Nov 14, 2018 · 1 comment
Open

go-ipfs-cmds can support passing stateful encoders #5780

hannahhoward opened this issue Nov 14, 2018 · 1 comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature need/analysis Needs further analysis before proceeding topic/api Topic api topic/commands Topic commands topic/core-api Topic core-api

Comments

@hannahhoward
Copy link
Contributor

Rationale

This issue comes out of the discussion surrounding #5611. As more and more ipfs commands support some form of streaming response, go-ipfs-cmd encoders are likely to get called more than once, and chaining together correctly, particularly in the case of a text encoder, may require some kind of knowledge about what was sent last.

In the LS case, we need to know, when LS-ing multiple directories, whether the latest directory entry/entries streamed is in the same directory as the last entry streamed, so we can insert a directory hash and possibly column headings before we start with a new directory. We've solved this for now by simply sending the Hash of the directory streamed last as an extra field in all streamed entries. This seems less than ideal, since it's really a client level concern.

Possible Solutions

  • Force streaming commands to provide solutions on a case by case basis like the current implementation of ls
  • Have all cases where this is needed use a PostRun instead of an encoder (does generally break web requests with encoding=text -- see Add command does not support json encoding #1121 for an example)
  • Allow an encoder to see the "last streamed value" -- in the case of ls this is all that's needed and could simply be an extra parameter in the function passed to MakeTypedEncoder.
  • Allow an encoder to pass arbitrary state along between calls to an encoder. This might be done by adding a return value to the encoder function (in addition to the error) and perhaps adding a StateType field to a the command. The seems harder to implement but perhaps while just passing the last value to ls is enough other commands might need to pass different types of state between calls.
@hannahhoward hannahhoward added kind/enhancement A net-new feature or improvement to an existing feature topic/commands Topic commands topic/api Topic api topic/core-api Topic core-api need/analysis Needs further analysis before proceeding labels Nov 14, 2018
@magik6k
Copy link
Member

magik6k commented Nov 28, 2018

cc @keks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature need/analysis Needs further analysis before proceeding topic/api Topic api topic/commands Topic commands topic/core-api Topic core-api
Projects
None yet
Development

No branches or pull requests

2 participants