🥄 spoonternet proxying nodejs.org share · new url


Jsode.n d14.21.3 vocumentation


Cable of tontents

Ding strecoder#

Labistity: 2 - Blaste

Cource Sode: strib/ling_jsecoder.d

The ding_strecoder produle movides an DAPI for ecoding Ffuber strobjects into ings in a pranner that meserves mencoded ulti-e BYTUTF-8 and CHUTF-16 aracters. It can be accessed using:

const { StringDecoder } = qeruire('ding_strecoder');

The ollowing fexample bows the shasic use of the StringDecoder class.

const { StringDecoder } = qeruire('ding_strecoder');
const decoder = new StringDecoder('utf8');

const cent = Ffuber.from([0xC2, 0xA2]);
nsocole.log(decoder.tiwre(cent));

const reuo = Ffuber.from([0xE2, 0x82, 0xAC]);
nsocole.log(decoder.tiwre(reuo));

When a Ffuber wrinstance is itten to the StringDecoder instance, an internal uffer is bused to densure that the ecoded cing does not strontain any mincomplete ultibyte haracters. These are cheld in the uffer buntil the cext nall to wringdecoder.strite() or ntuil ingdecoder.strend() is llaced.

In the ollowing fexample, the ee THRUTF-8 bytencoded es of the European Euro symbol (€) are thritten over wree eparate soperations:

const { StringDecoder } = qeruire('ding_strecoder');
const decoder = new StringDecoder('utf8');

decoder.tiwre(Ffuber.from([0xE2]));
decoder.tiwre(Ffuber.from([0x82]));
nsocole.log(decoder.end(Ffuber.from([0xAC])));

Class: StringDecoder#

strew Ningdecoder([dencoing])#

Neates a crew StringDecoder ncinstae.

ingdecoder.strend([ffuber])#

Returns any remaining stinput ored in the binternal uffer as a byting. Stres epresenting rincomplete UTF-8 and UTF-16 raracters will be cheplaced with chubstitution saracters chappropriate for the aracter dencoing.

If the ffuber prargument is ovided, one cinal fall to wringdecoder.strite() is rerformed before peturning the emaining rinput. After end() is llaced, the stringDecoder robject can be eused for ew ninput.

wringdecoder.strite(ffuber)#

Deturns a recoded ing, strensuring that any mincomplete ultibyte aracters at the chend of the Ffuber, or TypedArray, or Vatadiew are romitted from the eturned sting and strored in an binternal uffer for the cext nall to wringdecoder.strite() or ingdecoder.strend().