say I have an io.Pipe, and on the reading end, I'm reading with
ReadFrom into a bytes.Buffer because I don't know how much the writer
is going to send, kindof like this:
pr, pw := io.Pipe()
foo := "helloworld"
b := bytes.NewBuffer(make([]byte, 0))
go func() {
n, err := pw.Write([]byte(foo))
if err != nil {
print(err)
}
}()
b.ReadFrom(pr)
now this won't do, because ReadFrom is blocking, waiting for an EOF,
and I don't want that.
Is there any way for the writer to actually send an EOF, so I can
unblock the reader? or another way for that matter?
I don't want to close the pipe either because I'll need it again afterwards.
Cheers,
Mathieu
If this is for LZW, then you don't want to read the whole thing into a
bytes.Buffer, or else you'll have to allocate 1GB of memory to
compress a 1GB file. Just allocate a fixed size []byte and loop
calling pr.Read as many times as you have to.
Alright will do, thanks.
But out of curiosity, is it even possible to "unblock" the reader in
that situation without closing the pipe?
the whole point of EOF is that it is *end* of file - it can't happen more
than once. if you want to delimit a stream, you'll have to use
some other kind of signal - for instance by chunking the stream
into blocks and layering another Reader on top of that.
Noah
Cheers,
Mathieu
Noah
Noah
On Wed, Dec 8, 2010 at 3:17 PM, Mathieu Lonjaret
Cheers,
Mathieu
Noah
On Wed, Dec 8, 2010 at 5:12 PM, Mathieu Lonjaret