Encoding

Last updated Apr 23, 2026

TextEncoder

Background

The TextEncoder takes a stream of code points as input and emits a stream of bytes. Encoding types passed to the constructor are ignored and a UTF-8 TextEncoder is created.

TextEncoder() ↗︎ returns a newly constructed TextEncoder that generates a byte stream with UTF-8 encoding. TextEncoder takes no parameters and throws no exceptions.

Constructor

let encoder = new TextEncoder();

Properties

  • encoder.encoding DOMString read-only
  • The name of the encoder as a string describing the method the TextEncoder uses (always utf-8).

Methods

  • encode(inputUSVString) : Uint8Array
  • Encodes a string input.

TextDecoder

Background

The TextDecoder interface represents a UTF-8 decoder. Decoders take a stream of bytes as input and emit a stream of code points.

TextDecoder() ↗︎ returns a newly constructed TextDecoder that generates a code-point stream.

Constructor

let decoder = new TextDecoder();

Properties

  • decoder.encoding DOMString read-only
  • The name of the decoder that describes the method the TextDecoder uses.
  • decoder.fatal boolean read-only
  • Indicates if the error mode is fatal.
  • decoder.ignoreBOM boolean read-only
  • Indicates if the byte-order marker is ignored.

Methods

Was this helpful?

YesNo

On this page

Encoding - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/runtime-apis/encoding/#page","headline":"Encoding","description":"Takes a stream of code points as input and emits a stream of bytes.","url":"https://developers.cloudflare.com/workers/runtime-apis/encoding/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/runtime-apis/encoding/og.png?v=b1daf4414d9a5d22","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: EventSource is a server-sent event API that allows a server to push events to a client. title: EventSource image: https://developers.cloudflare.com/workers/runtime-apis/eventsource/og.png?v=afd460dee7b0c619


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.