Open mraleph opened 7 years ago
True, it probably could be a Sink<List<int>>
. Not that the close
method would do anything useful, but still, it's definitely doable.
Would a Sink
be enough, or do you see wrappers for IOSink
? (in which case there would be an addStream
too).
I think it needs to be a StreamConsumer
to be ultimately useful.
I think it would be too much to make it a StreamConsumer
. It is a simple class that has one job. Trying to make it do more jobs at the same time is just over-complicating things (and failing at separation of concerns).
Even making it a Sink
is suspicious - why is this a Sink
and List
isn't?
I'd rather have good wrappers that can adapt something with an add
method to be a Sink
, and any Sink
to a StreamConsumer
. Adding close
method to BytesBuilder
makes no sense on its own - should you call it or not?
Maybe, a better option would be to have something like:
var builder = new BytesBuilder();
var sink = new IOSink.wrapping(builder);
I think that would be better. Then the only class worrying about the IOSink
interface is the IOSink
class, not the unrelated BytesBuilder
.
It would be nice if the IOSink
could wrap other objects too, but since the only relevant method on BytesBuilder
is add(List<int>)
, there probably isn't any common interface of things to wrap
What about moving it to dart:typed_data
?
I can see a lot of examples on the web hand-rolling sinks on top of
BytesBuilder
. It would be much easier ifBytesBuilder
actually was a sink./cc @lrhn @floitschG @mkustermann