-
Notifications
You must be signed in to change notification settings - Fork 55
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
TextEncoderStream and TextDecoderStream #282
Comments
Hey Adam, Thanks for filing for a review, and apologies for the delay in getting back to you. Some questions regarding the merged PR:
Regards |
To answer the first question, other encodings don't have a BOM. If you encoded U+FEFF with, e.g., gb18030 it should never be removed. |
Thanks, @annevk! Is there an equivalent mechanism to handle potentially special characters in other encodings that could be pluggable? |
No such characters exist to my knowledge and we intentionally don't want text encodings to be generic, we want everyone to migrate to UTF-8. |
I'm not sure I understand the question correctly. They're not magically faster. Implementations can take advantage of the fact that the internals are not visible to user JS to optimise these operations. But they wouldn't be faster because of features unavailable to JS; they'd be faster because of the absence of the dynamic behaviour provided by JS. They're also not more flexible. A transform stream is just a readable and a writable glued together, and that is what GenericTransformStream is trying to express. That glue can be written in JS or anything else. The polyfill at https://github.com/GoogleChromeLabs/text-encode-transform-polyfill has full feature parity with Chrome's implementation, which I think demonstrates that layering has not been broken. The queuing strategies with which the streams are constructed are intentionally not configurable. To avoid adding buffer bloat to pipes, I made the queues as small as possible. My philosophy is that queuing strategies should be designed together with the transformer, as mismatches can have surprising side-effects.
The first three demos at https://streams.spec.whatwg.org/demos/ use a polyfill of this functionality. Unfortunately it is out-of-date and doesn't match the final API. I am planning to update the demos to use the new polyfill, after which I can link them from the explainer. It would good to have a longer example in the standard as well, maybe with the other long examples at the start of section 7. @annevk, what do you think?
You can create a TransformStream for any encoding you want, but you have to provide your own implementation. Encoding to encodings other than UTF-8 is intentionally not exposed to the web platform. It wouldn't be a subtype of TextEncoderStream, but I don't know why you'd want to do that anyway. |
(I'm always supportive of more examples being added.) |
Thanks all, and sorry for the slow replies. So pulling on the
Regards |
This isn't correct. You can easily subclass TransformStream; try it in your browser to see! The hierarchy is open to anyone to extend. There's nothing magical about IsTransformStream. It tests whether you are a TransformStream or subclass of TransformStream. Furthermore, it is only used within the getters of TransformStream itself, to ensure you can't do something like |
By "this type", do you mean TransformStreamDefaultController? It can't be meaningfully subclassed, because it is only useful when it is associated with a TransformStream object.
A transform stream is simply an object that has a
You can always add buffering to a pipe using identity transforms. For example, suppose you want a megabyte of buffering in front of a TextDecoderStream: const bufferingIdentityTransform =
new TransformStream({}, new ByteLengthQueuingStrategy({highWaterMark: 1024 * 1024}));
response.body
.pipeThrough(bufferingIdentityTransform)
.pipeThrough(new TextDecoderStream())
.pipeTo(mySink);
There might be other platform transforms for which a configurable queuing strategy would make sense. There would be a price to pay in that the user-supplied
Indeed. I will let you know when they are updated. |
Thanks for the note on subclassing @ricea: yes, I was surprised to see: class TransformStreamDefaultController {
constructor() // always throws
... Given what you've shown above re: identity streams, what's the argument for preventing subclassing? On updated, examples, thanks. Looking forward to it. |
A Suppose hypothetically that we permitted constructing a "detached" So preventing subclassing reduces complexity with no loss of generality. |
@domenic if you are supposed to subclass TransformStream shouldn't the examples in the stream spec do that? eg. https://streams.spec.whatwg.org/#example-ts-lipfuzz |
You're not supposed to; you can. Sometimes it's useful, like when you want to add extra properties and methods! In those examples it's not, because we just want to transform some data. |
The argument that "we can't figure out why a web developer would ever want something" (a something that works against our design principles and general design goals) is not particularly compelling. The point of extensibility is to enable developers to do the set of things we haven't yet thought of, rather than to presume that we're omniscient. The argument from consistency, at least, trumps one-off restrictions and design oddities. Let's make this subclassable. |
I think you are over-applying a general principle, which doesn't make sense in the case of the revealing constructor pattern. Those revealed capabilities aren't really a proper "class"; they're a holder for some capabilities of another class (in this case TransformStream), which itself is subclassable and extensible in the desired way. This ties in to how you have misquoted @ricea's argument. It isn't "we can't figure out why a web developer would want to do something". It's "preventing subclassing reduces complexity with no loss of generality": i.e., anything a web developer might want to do, they can do in a much simpler way with other techniques. |
@kenchris and I discussed during the Iceland F2F. As we see it, the fact on whether or not we force inheritance in this particular case is not a significant blocker and we'd like to see this feature move forward. Thanks for bringing this to our attention and bearing with us for the extremely long discussion. |
Hello TAG!
I'm requesting a TAG review of:
Further details (optional):
You should also know that...
This is an extension to the existing Encoding Standard to integrate with the Streams Standard. There has been extensive discussion at whatwg/encoding#72.
We'd prefer the TAG provide feedback as (please select one):
The text was updated successfully, but these errors were encountered: