Re: [whatwg/encoding] TextEncoder#encode - write to existing Uint8Array (#69)

Strawman API proposal: `encodeInto(view, string, offset = 0)`. Example use:
```javascript
let offset = 0;
while (offset < string.length) {
  offset = encoder.encodeInto(view, string, offset);
  if (offset < string.length) {
    view = getANewViewSomehow();
  }
}
```
`encodeInto()` would always write the maximum number of code points that it can without overflowing _view_. Incomplete utf-8 sequences would not be written. Unused bytes at the end of _view_ would not be touched.

As @hsivonen noted, implementations would probably fall back to a slower algorithm when they get close to the end of the output buffer.

-- 
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/69#issuecomment-433928708

Received on Monday, 29 October 2018 14:23:57 UTC