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
Move/copy IOSink to dart:typed_data #17293
Comments
cc @skabet. |
We've taken the first step in this process, by initiating a move of _StreamSinkImpl to dart:async as StreamSinkAdapter. CL: https://codereview.chromium.org/196423021 This provides most of the logic for the IOSink, and should be sufficient in some cases. Now, the remaining question is what should happen to IOSink. Some possibilities:
What do you think? cc @floitschG. |
👍
I'm okay with any of the last three of those. I'd prefer #2 or #3, since I think it's useful for users to be able to use the same API in dart:io that they do elsewhere. Anders was reticent about adding a dependency from dart:typed_data onto dart:async, so #3 may be the best option overall. |
Agree with moving it to dart:convert |
Disagree with moving to convert. If you want a StringSink on top of a StreamSink in dart:convert, I would prefer a wrapper, not an extension. The class in dart:convert should not expose the StreamSink interface. This is really about writing binary data interleaved with text, not about converting. I think it fits well in dart:io for that, or in a helper package. |
I don't think this is quite right. It's about being able to write binary data or text; I don't think interleaving is the issue so much as being able to choose either mode with minimal fuss. When someone is writing to an HTTP stream or a file, they need the ability to write binary data, but the majority of the time in practice they want to write text. This interface makes that easy. I'd also contend that writing text to something that expects binary data is fundamentally about converting.
I don't understand this claim. Practically everything dart:io does with IOSink also needs to be done in the browser where dart:io is unavailable. The browser needs to make HTTP requests, it needs to write to files, it needs to communicate with sockets. If IOSink is a good interface for that on the server (which I think it is), it should also be made available on the client.
In a helper package it's unavailable to dart:io. |
If that is an either-or, the StreamSink<List<int>> handles the binary data If the use case is to send binary data and text to the same receiver, it You can get that behavior with a simple wrapper around Actually, I notice that ChunkedConversionSink is such a general type that Absolutely. So you use a converter. I just don't think the converter and I guess my problem is that I don't think it's a good basic interface. Sure, It is easy to make. We can make a mixin that does it: it converts every Does it need an interface? It's just a class that is both a StreamSink and |
It sounds like you don't like IOSink in general. If so, why is it even in dart:io? In general, I agree that it's good to have separate classes for separate jobs. However, there are cases where convenience is an overriding concern. You don't want users to always have to write The problem is that we can't then expose the same interface (and leverage the users' familiarity with it) anywhere else. A package that wants to support both dart:io and dart:html has to reinvent the wheel/ |
I don't particularly like IOSink as a general interface. Mainly because it isn't very general. But that's done now. For the current problem, first notice that there are two problems being solved by IOSink: Adapting a StreamConsumer to be a StreamSink, and extending a StreamSink to also be a StringSink. Now that we are trying to generalize the interface and implementation, we have put the adapter in dart:async. If we also want an interface that is both a StreamSink and a StringSink, with the StringSink delegating to the StreamSink through a converter, then I would still put the interface in dart:async. The class is still primarily a StreamSink, it just has extra helper methods for adding text data as bytes, which internally uses dart:convert functionality. The StringStreamSink interface will just be: Then dart:io can have an implementation of this interface. We can also add a mixin class that allows adding the conversion features on top of any StreamSink<List<int>>. I don't think we should have an actual public implementation on top of StreamSinkAdapter (except for what dart:io wants to have), because that is combining the two independent concerns (adapter, string extension) which should not be done at a generic level, but only in an actual specialized implementation class that combines the features it needs for a particular task. So my suggestion is:
|
That sounds reasonable, but I'm still worried about how difficult it is to create a StringSink that emits a Stream<List<int>>. What would the code snippet be to make a StringSink given a StreamController<List<int>>? |
You can do: That |
Is there any way we can consolidate that? It seems very difficult for users to write. Maybe something like: new ChunkedStringController(encoding: UTF8) where ChunkedStringController is both a StringSink and a StreamController<List<int>>. My goal here is to make it easy for a user to expose a byte stream that can be written to with strings. |
Agreeing with #12 Also, having a settable encoding on IOSink feels a bit broken. |
Removed Type-Defect label. |
If this is still necessary, I think the |
IOSink provides a useful interface for writing strings to streams of bytes, but it's sadly restricted to dart:io. This means that it's not safe to use in packages that want to support multiple platforms, such as the http package.
I suggest that it be moved to dart:typed_data as a ByteSink class. For the short term, IOSink can inherit from this class (or its interface), thus avoiding backwards incompatibility while maintaining compatibility.
The text was updated successfully, but these errors were encountered: