Name: text-encode-transform-prollyfill
Owner: GoogleChromeLabs
Description: Prollyfill for using TextEncoder and TextDecoder as transform streams
Created: 2017-02-22 01:42:19.0
Updated: 2018-05-22 06:34:40.0
Pushed: 2018-05-22 06:36:01.0
Size: 36
Language: HTML
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is a prollyfill for the transform streams TextEncoderStream and TextDecoderStream. It is based on the draft changes to the Encoding Standard here:
http://htmlpreview.github.io/?https://github.com/ricea/encoding-streams/blob/master/patch.html
However, it may be out-of-sync with that document.
This is intended for experimentation and development of the standard.
You need implementations of TextEncoder, TextDecoder, ReadableStream, WritableStream and TransformStream, either natively or via polyfill.
Include the prollyfill in the page:
ipt src="text-encode-transform.js">
It can also be used in a Worker environment:
rtScripts('text-encode-transform.js');
Then you can use it in a pipe like this:
Source
ipeThrough(new TextDecoderStream())
ipeTo(textDestination);
Any arguments that the TextDecoder constructor normally accepts will also work when used as a stream transform.
TextEncoderStream works the same way:
Source
ipeThrough(new TextEncoderStream())
ipeTo(byteDestination);
Tests in web-platform-test format are included in the tests/ directory. The tests use infrastructure from the https://github.com/w3c/web-platform-tests repository. You will need to run the tests under the web-platform-tests HTTP server.
The tests expect the TransformStream polyfill to be installed in a parallel directory to this one named transform-stream-polyfill. You can get the polyfill from https://github.com/whatwg/streams/blob/transform-stream-polyfill/reference-implementation/contrib/transform-stream-polyfill.js
The tests import the polyfills from tests/resources. By default symbolic links are used; if they don't work in your environment they can just be copied there. If your browser supports TransformStream natively then replacing tests/releases/transform-stream.js with an empty file should work.
This is not an official Google product.