Re: [whatwg/encoding] Add Streams support (#72)

Here's my attempt at descriptive sample code:

Constructor version:
```javascript
const decoder = new TextDecoder('shift-jis', {fatal: true});
fetch('data').then(response =>
  response.body
      .pipeThrough(decoder)
      .pipeTo(sink)
);
// Even if 'data' ended in the middle of a character, it makes no
// difference to decode().
console.log(decoder.decode(new Uint8Array([0x81, 0x5a]))); // 〇
```

Static method version:
```javascript
const decoder = TextDecoder.stream('shift-jis', {fatal: true});
fetch('data').then(response => {
  response.body
      .pipeThrough(decoder)
      .pipeTo(sink);
});
// decoder only has 'readable' and 'writable' properties.
console.log('decode' in decoder); // false
```

It's difficult to capture all the differences in semantics in a short snippet. Let me know if you think we need more/less.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/issues/72#issuecomment-372601600

Received on Tuesday, 13 March 2018 09:31:24 UTC