11cb0ef41Sopenharmony_ci{
21cb0ef41Sopenharmony_ci  "type": "module",
31cb0ef41Sopenharmony_ci  "source": "doc/api/string_decoder.md",
41cb0ef41Sopenharmony_ci  "modules": [
51cb0ef41Sopenharmony_ci    {
61cb0ef41Sopenharmony_ci      "textRaw": "String decoder",
71cb0ef41Sopenharmony_ci      "name": "string_decoder",
81cb0ef41Sopenharmony_ci      "introduced_in": "v0.10.0",
91cb0ef41Sopenharmony_ci      "stability": 2,
101cb0ef41Sopenharmony_ci      "stabilityText": "Stable",
111cb0ef41Sopenharmony_ci      "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v18.20.1/lib/string_decoder.js\">lib/string_decoder.js</a></p>\n<p>The <code>node:string_decoder</code> module provides an API for decoding <code>Buffer</code> objects\ninto strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16\ncharacters. It can be accessed using:</p>\n<pre><code class=\"language-js\">const { StringDecoder } = require('node:string_decoder');\n</code></pre>\n<p>The following example shows the basic use of the <code>StringDecoder</code> class.</p>\n<pre><code class=\"language-js\">const { StringDecoder } = require('node:string_decoder');\nconst decoder = new StringDecoder('utf8');\n\nconst cent = Buffer.from([0xC2, 0xA2]);\nconsole.log(decoder.write(cent)); // Prints: ¢\n\nconst euro = Buffer.from([0xE2, 0x82, 0xAC]);\nconsole.log(decoder.write(euro)); // Prints: €\n</code></pre>\n<p>When a <code>Buffer</code> instance is written to the <code>StringDecoder</code> instance, an\ninternal buffer is used to ensure that the decoded string does not contain\nany incomplete multibyte characters. These are held in the buffer until the\nnext call to <code>stringDecoder.write()</code> or until <code>stringDecoder.end()</code> is called.</p>\n<p>In the following example, the three UTF-8 encoded bytes of the European Euro\nsymbol (<code>€</code>) are written over three separate operations:</p>\n<pre><code class=\"language-js\">const { StringDecoder } = require('node:string_decoder');\nconst decoder = new StringDecoder('utf8');\n\ndecoder.write(Buffer.from([0xE2]));\ndecoder.write(Buffer.from([0x82]));\nconsole.log(decoder.end(Buffer.from([0xAC]))); // Prints: €\n</code></pre>",
121cb0ef41Sopenharmony_ci      "classes": [
131cb0ef41Sopenharmony_ci        {
141cb0ef41Sopenharmony_ci          "textRaw": "Class: `StringDecoder`",
151cb0ef41Sopenharmony_ci          "type": "class",
161cb0ef41Sopenharmony_ci          "name": "StringDecoder",
171cb0ef41Sopenharmony_ci          "methods": [
181cb0ef41Sopenharmony_ci            {
191cb0ef41Sopenharmony_ci              "textRaw": "`stringDecoder.end([buffer])`",
201cb0ef41Sopenharmony_ci              "type": "method",
211cb0ef41Sopenharmony_ci              "name": "end",
221cb0ef41Sopenharmony_ci              "meta": {
231cb0ef41Sopenharmony_ci                "added": [
241cb0ef41Sopenharmony_ci                  "v0.9.3"
251cb0ef41Sopenharmony_ci                ],
261cb0ef41Sopenharmony_ci                "changes": []
271cb0ef41Sopenharmony_ci              },
281cb0ef41Sopenharmony_ci              "signatures": [
291cb0ef41Sopenharmony_ci                {
301cb0ef41Sopenharmony_ci                  "return": {
311cb0ef41Sopenharmony_ci                    "textRaw": "Returns: {string}",
321cb0ef41Sopenharmony_ci                    "name": "return",
331cb0ef41Sopenharmony_ci                    "type": "string"
341cb0ef41Sopenharmony_ci                  },
351cb0ef41Sopenharmony_ci                  "params": [
361cb0ef41Sopenharmony_ci                    {
371cb0ef41Sopenharmony_ci                      "textRaw": "`buffer` {string|Buffer|TypedArray|DataView} The bytes to decode.",
381cb0ef41Sopenharmony_ci                      "name": "buffer",
391cb0ef41Sopenharmony_ci                      "type": "string|Buffer|TypedArray|DataView",
401cb0ef41Sopenharmony_ci                      "desc": "The bytes to decode."
411cb0ef41Sopenharmony_ci                    }
421cb0ef41Sopenharmony_ci                  ]
431cb0ef41Sopenharmony_ci                }
441cb0ef41Sopenharmony_ci              ],
451cb0ef41Sopenharmony_ci              "desc": "<p>Returns any remaining input stored in the internal buffer as a string. Bytes\nrepresenting incomplete UTF-8 and UTF-16 characters will be replaced with\nsubstitution characters appropriate for the character encoding.</p>\n<p>If the <code>buffer</code> argument is provided, one final call to <code>stringDecoder.write()</code>\nis performed before returning the remaining input.\nAfter <code>end()</code> is called, the <code>stringDecoder</code> object can be reused for new input.</p>"
461cb0ef41Sopenharmony_ci            },
471cb0ef41Sopenharmony_ci            {
481cb0ef41Sopenharmony_ci              "textRaw": "`stringDecoder.write(buffer)`",
491cb0ef41Sopenharmony_ci              "type": "method",
501cb0ef41Sopenharmony_ci              "name": "write",
511cb0ef41Sopenharmony_ci              "meta": {
521cb0ef41Sopenharmony_ci                "added": [
531cb0ef41Sopenharmony_ci                  "v0.1.99"
541cb0ef41Sopenharmony_ci                ],
551cb0ef41Sopenharmony_ci                "changes": [
561cb0ef41Sopenharmony_ci                  {
571cb0ef41Sopenharmony_ci                    "version": "v8.0.0",
581cb0ef41Sopenharmony_ci                    "pr-url": "https://github.com/nodejs/node/pull/9618",
591cb0ef41Sopenharmony_ci                    "description": "Each invalid character is now replaced by a single replacement character instead of one for each individual byte."
601cb0ef41Sopenharmony_ci                  }
611cb0ef41Sopenharmony_ci                ]
621cb0ef41Sopenharmony_ci              },
631cb0ef41Sopenharmony_ci              "signatures": [
641cb0ef41Sopenharmony_ci                {
651cb0ef41Sopenharmony_ci                  "return": {
661cb0ef41Sopenharmony_ci                    "textRaw": "Returns: {string}",
671cb0ef41Sopenharmony_ci                    "name": "return",
681cb0ef41Sopenharmony_ci                    "type": "string"
691cb0ef41Sopenharmony_ci                  },
701cb0ef41Sopenharmony_ci                  "params": [
711cb0ef41Sopenharmony_ci                    {
721cb0ef41Sopenharmony_ci                      "textRaw": "`buffer` {string|Buffer|TypedArray|DataView} The bytes to decode.",
731cb0ef41Sopenharmony_ci                      "name": "buffer",
741cb0ef41Sopenharmony_ci                      "type": "string|Buffer|TypedArray|DataView",
751cb0ef41Sopenharmony_ci                      "desc": "The bytes to decode."
761cb0ef41Sopenharmony_ci                    }
771cb0ef41Sopenharmony_ci                  ]
781cb0ef41Sopenharmony_ci                }
791cb0ef41Sopenharmony_ci              ],
801cb0ef41Sopenharmony_ci              "desc": "<p>Returns a decoded string, ensuring that any incomplete multibyte characters at\nthe end of the <code>Buffer</code>, or <code>TypedArray</code>, or <code>DataView</code> are omitted from the\nreturned string and stored in an internal buffer for the next call to\n<code>stringDecoder.write()</code> or <code>stringDecoder.end()</code>.</p>"
811cb0ef41Sopenharmony_ci            }
821cb0ef41Sopenharmony_ci          ],
831cb0ef41Sopenharmony_ci          "signatures": [
841cb0ef41Sopenharmony_ci            {
851cb0ef41Sopenharmony_ci              "params": [
861cb0ef41Sopenharmony_ci                {
871cb0ef41Sopenharmony_ci                  "textRaw": "`encoding` {string} The character [encoding][] the `StringDecoder` will use. **Default:** `'utf8'`.",
881cb0ef41Sopenharmony_ci                  "name": "encoding",
891cb0ef41Sopenharmony_ci                  "type": "string",
901cb0ef41Sopenharmony_ci                  "default": "`'utf8'`",
911cb0ef41Sopenharmony_ci                  "desc": "The character [encoding][] the `StringDecoder` will use."
921cb0ef41Sopenharmony_ci                }
931cb0ef41Sopenharmony_ci              ],
941cb0ef41Sopenharmony_ci              "desc": "<p>Creates a new <code>StringDecoder</code> instance.</p>"
951cb0ef41Sopenharmony_ci            }
961cb0ef41Sopenharmony_ci          ]
971cb0ef41Sopenharmony_ci        }
981cb0ef41Sopenharmony_ci      ],
991cb0ef41Sopenharmony_ci      "type": "module",
1001cb0ef41Sopenharmony_ci      "displayName": "String decoder"
1011cb0ef41Sopenharmony_ci    }
1021cb0ef41Sopenharmony_ci  ]
1031cb0ef41Sopenharmony_ci}