Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Prollyfill for using TextEncoder and TextDecoder as transform streams

License

Notifications You must be signed in to change notification settings

GoogleChromeLabs/text-encode-transform-polyfill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text Encode Transformations

Overview

This is a polyfill for the transform streams TextEncoderStream and TextDecoderStream. It is based on the TextEncoderStream and TextDecoderStream interfaces from the Encoding Standard:

https://encoding.spec.whatwg.org/#interface-textdecoderstream

It is intended for experimentation with the standard.

Requirements

You need implementations of TextEncoder, TextDecoder, ReadableStream, WritableStream and TransformStream, either natively or via polyfill.

How to use

Include the polyfill in the page:

<script src="text-encode-transform.js">

It can also be used in a Worker environment:

importScripts('text-encode-transform.js');

Then you can use it in a pipe like this:

byteSource
  .pipeThrough(new TextDecoderStream())
  .pipeTo(textDestination);

Any arguments that the TextDecoder constructor normally accepts will also work when used as a stream transform.

TextEncoderStream works the same way:

textSource
  .pipeThrough(new TextEncoderStream())
  .pipeTo(byteDestination);

Tests

Tests have moved to the main web-platform-tests repository at https://github.com/web-platform-tests/wpt/tree/master/encoding/streams.

See also

Disclaimer

This is not an official Google product.

About

Prollyfill for using TextEncoder and TextDecoder as transform streams

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages