Does `ipfs cat` stream output?

Hi,

I am reviewing the core cat.go cmd https://github.com/ipfs/go-ipfs/blob/1c6043d67ca1301573f0650cf0a227cd3386bb4f/core/commands/cat.go#L61 but there is too much abstraction for me to come to a conclusion.

Does the cat cmd streams the output or it loads the whole file to memory and then it returns it?

If yes, can you point me to the part where it streams to and to which output?

I see the progress bar is streamed to os.Stderr. Why to os.Stderr btw?

bar, reader := progressBarForReader(os.Stderr, val, int64(res.Length()))

Thanks!

Does the cat cmd streams the output or it loads the whole file to memory and then it returns it?

It streams.

I see the progress bar is streamed to os.Stderr. Why to os.Stderr btw?

Because the output is sent to stdout.

Thanks Stebalien. Just wanted to confirm. I think I also just found the code for configuring the os.Stdout

core/commands/config.go

func editConfig(filename string) error {
	editor := os.Getenv("EDITOR")
	if editor == "" {
		return errors.New("ENV variable $EDITOR not set")
	}

	cmd := exec.Command("sh", "-c", editor+" "+filename)
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Run()
}
/core/commands/external.go

			r, w := io.Pipe()

			cmd := exec.Command(binname, req.Arguments()...)

			// TODO: make commands lib be able to pass stdin through daemon
			//cmd.Stdin = req.Stdin()
			cmd.Stdin = io.LimitReader(nil, 0)
			cmd.Stdout = w
			cmd.Stderr = w

Will continue be digging into this :slight_smile:

How do I mark this topic as resolved please?

core/commands/config.go

func editConfig(filename string) error {
	editor := os.Getenv("EDITOR")
	if editor == "" {
		return errors.New("ENV variable $EDITOR not set")
	}

	cmd := exec.Command("sh", "-c", editor+" "+filename)
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Run()
}

This is the code for editing the config (unrelated).

/core/commands/external.go

			r, w := io.Pipe()

			cmd := exec.Command(binname, req.Arguments()...)

			// TODO: make commands lib be able to pass stdin through daemon
			//cmd.Stdin = req.Stdin()
			cmd.Stdin = io.LimitReader(nil, 0)
			cmd.Stdout = w
			cmd.Stderr = w

This is the code for calling “external” commands, also not related.

I’d start at /cmd/ipfs/main.go.

How do I mark this topic as resolved please?

Unfortunately, discourse doesn’t have a feature for that and we don’t
have any conventions around changing the title. Just leave it as is.