StringDecoder
node:string_decoder ↗は、WHATWG標準のTextEncoderおよびTextDecoder APIよりも前に存在したレガシーなユーティリティモジュールです。ほとんどの場合、TextEncoderとTextDecoderを代わりに使用するべきです。StringDecoderは、既存のnpmパッケージとの互換性のために主にWorkersランタイムで利用可能です。StringDecoderは次のようにアクセスできます:
const { StringDecoder } = require('node:string_decoder');const decoder = new StringDecoder('utf8');
const cent = Buffer.from([0xC2, 0xA2]);console.log(decoder.write(cent));
const euro = Buffer.from([0xE2, 0x82, 0xAC]);console.log(decoder.write(euro));詳細については、Node.jsのstring_decoderドキュメント ↗を参照してください。