![// Just use the TextDecoder constructor: const decoder = new TextDecoder('shift-jis', {fatal: true}); fetch('data').then(response => response.body .pipeThrough(decoder) .pipeTo(sink) ); // While it's being used as a transform stream, its decode() API // can be used independently of its readable/writable properties: setInterval(() => { console.log(decoder.decode(new Uint8Array([0x81, 0x5a]))); // 〇 },](https://pbs.twimg.com/media/DYKxHNFUQAA1ZQs.jpg?name=small&format=webp)
ALT // Just use the TextDecoder constructor: const decoder = new TextDecoder('shift-jis', {fatal: true}); fetch('data').then(response => response.body .pipeThrough(decoder) .pipeTo(sink) ); // While it's being used as a transform stream, its decode() API // can be used independently of its readable/writable properties: setInterval(() => { console.log(decoder.decode(new Uint8Array([0x81, 0x5a]))); // 〇 },

ALT // Use a separate static stream() factory method: 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; // no decode() method or TextDecoder instance is involved. console.log('decode' in decoder); // false

