Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(375)

Issue 4969056: code review 4969056: io: add a Tee (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 4 months ago by lvd
Modified:
14 years, 4 months ago
Reviewers:
adg, rsc, hector
CC:
golang-dev
Visibility:
Public.

Description

io: add a Tee io.MultiReader is like unix cat, and MultiWriter is like unix tee, but it is a writer. I needed a reader that did tee (for forwarding an html PUT request to a bunch of other servers).

Patch Set 1 #

Patch Set 2 : diff -r 1cd42fb11eea https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 1cd42fb11eea https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 1cd42fb11eea https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+169 lines, -0 lines) Patch
M src/pkg/io/Makefile View 1 1 chunk +1 line, -0 lines 0 comments Download
A src/pkg/io/tee.go View 1 1 chunk +99 lines, -0 lines 0 comments Download
A src/pkg/io/tee_test.go View 1 1 chunk +69 lines, -0 lines 0 comments Download

Messages

Total messages: 10
lvd
Hello adg@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
14 years, 4 months ago (2011-09-03 11:18:58 UTC) #1
hector
Snap! I added something like this a little over a week ago. Mine's called io.TeeReader, ...
14 years, 4 months ago (2011-09-03 15:32:05 UTC) #2
lvd
i dont want the slowest reader to block the others On Sep 3, 2011 5:32 ...
14 years, 4 months ago (2011-09-04 08:54:40 UTC) #3
hector
Ok. But just for the record this criticism can be addressed by making the pipes ...
14 years, 4 months ago (2011-09-04 09:20:46 UTC) #4
lvd
On Sun, Sep 4, 2011 at 11:20, Hector Chu <hectorchu@gmail.com> wrote: > Ok. But just ...
14 years, 4 months ago (2011-09-04 13:34:08 UTC) #5
rsc
I think the existing io.TeeReader should suffice. The Tee in this CL is very customized: ...
14 years, 4 months ago (2011-09-04 16:33:21 UTC) #6
lvd
On Sun, Sep 4, 2011 at 18:33, Russ Cox <rsc@golang.org> wrote: > I think the ...
14 years, 4 months ago (2011-09-04 18:50:22 UTC) #7
lvd
*** Abandoned ***
14 years, 4 months ago (2011-09-04 18:54:15 UTC) #8
adg
On 5 September 2011 02:33, Russ Cox <rsc@golang.org> wrote: > I think the existing io.TeeReader ...
14 years, 4 months ago (2011-09-04 23:39:41 UTC) #9
rsc
14 years, 3 months ago (2011-09-05 12:01:04 UTC) #10
I took another look at the code.
You are right: it does less than I thought.

That said, it is not like tee(1).
Tee(1) is about writing out a copy as the data
flows through, which is what TeeReader does,
and does well.  Also, I disagree strongly that
TeeReader introduces "new semantics on the
Reader class."

What is the context in which this CL's Tee is useful?
You have written off the fact that it requires an
infinite buffer as a TODO, but that is very
fundamental to the way you've laid it out,
since you also said you don't want the slowest
reader to block the others.  You can't both have
a buffer limit and keep the slowest reader from
blocking the others.

If there is no buffer limit, then I would argue that

data, err := ioutil.ReadAll(r)
tap1 := bytes.NewBuffer(data)
tap2 := bytes.NewBuffer(data)
tap3 := bytes.NewBuffer(data)

works as nicely with less code.

If there is a limit, then you have to do something
to keep them all in sync.  One very good way to
do this is to turn the I/O around so that the data is
being pushed out to the sinks, by using a Writer
and maybe even an io.Pipe.

Most fundamentally, I don't think this is a very
common situaton to be in.  Programs typically
use Readers for input and Writers for output.
That means that data moving toward the program
is a Reader and data moving away is a Writer.
Pipe means everything can be converted the
other way for the general case and lets the APIs
focus on the common cases.  The common case
is tee(1), which is TeeReader.

Russ
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b