Remove TextEncoder call on write to stream
# workers-help
r
I'm diving into streaming responses and I see myself writing this:
Copy code
ts
await writer.write(encoder.encode('<h1>Hello world!</h1>'));
Is this the right way of appending strings or is it possible to remove the
encoder.encode
call of the
TextEndoer
?
n
That is the correct way, I would say. You can write different type of buffers but since you're writing UTF-8 text, you have to encode it first to an unsigned integer array via TextEncoder. > The underlying stream may accept fewer kinds of type than any, it will throw an exception when encountering an unexpected type.
Cases when you don't need to encode it is when you're already dealing with a buffer via a stream, for example: