KKitForma.

Language

EnglishEnglishTürkçeTurkishGuide unavailable in this language · open toolsDeutschGermanGuide unavailable in this language · open toolsEspañolSpanishGuide unavailable in this language · open toolsFrançaisFrenchGuide unavailable in this language · open toolsPortuguêsPortugueseGuide unavailable in this language · open toolsItalianoItalianGuide unavailable in this language · open toolsNederlandsDutchGuide unavailable in this language · open toolsPolskiPolishGuide unavailable in this language · open toolsРусскийRussianGuide unavailable in this language · open toolsУкраїнськаUkrainianGuide unavailable in this language · open toolsSvenskaSwedishGuide unavailable in this language · open toolsNorskNorwegianGuide unavailable in this language · open toolsDanskDanishGuide unavailable in this language · open toolsSuomiFinnishGuide unavailable in this language · open toolsČeštinaCzechGuide unavailable in this language · open toolsRomânăRomanianGuide unavailable in this language · open toolsΕλληνικάGreekGuide unavailable in this language · open toolsالعربيةArabicGuide unavailable in this language · open toolsעבריתHebrewGuide unavailable in this language · open toolsفارسیPersianGuide unavailable in this language · open toolsاردوUrduGuide unavailable in this language · open toolsहिन्दीHindiGuide unavailable in this language · open toolsবাংলাBengaliGuide unavailable in this language · open toolsதமிழ்TamilGuide unavailable in this language · open toolsతెలుగుTeluguGuide unavailable in this language · open toolsमराठीMarathiGuide unavailable in this language · open toolsગુજરાતીGujaratiGuide unavailable in this language · open tools简体中文Chinese SimplifiedGuide unavailable in this language · open tools繁體中文Chinese TraditionalGuide unavailable in this language · open tools日本語JapaneseGuide unavailable in this language · open tools한국어KoreanGuide unavailable in this language · open toolsTiếng ViệtVietnameseGuide unavailable in this language · open toolsไทยThaiGuide unavailable in this language · open toolsBahasa IndonesiaIndonesianGuide unavailable in this language · open toolsBahasa MelayuMalayGuide unavailable in this language · open toolsFilipinoFilipinoGuide unavailable in this language · open toolsKiswahiliSwahiliGuide unavailable in this language · open toolsAfrikaansAfrikaansGuide unavailable in this language · open toolsMagyarHungarianGuide unavailable in this language · open toolsБългарскиBulgarianGuide unavailable in this language · open toolsHrvatskiCroatianGuide unavailable in this language · open toolsSrpskiSerbianGuide unavailable in this language · open toolsSlovenčinaSlovakGuide unavailable in this language · open toolsSlovenščinaSlovenianGuide unavailable in this language · open toolsLietuviųLithuanianGuide unavailable in this language · open toolsLatviešuLatvianGuide unavailable in this language · open toolsEestiEstonianGuide unavailable in this language · open toolsCatalàCatalanGuide unavailable in this language · open toolsEuskaraBasqueGuide unavailable in this language · open tools
← Questions & answers

KITFORMA · EDITORIAL ANSWER

Why does File.text corrupt a legacy Windows-encoded CSV?

KitForma editorial guide. Read legacy CSV bytes before decoding with the producer’s stated encoding; changing a filename cannot repair a UTF-8 mismatch.

HTML, CSS & accessibility →

Step-by-step answer

File.text() always decodes as UTF-8. A file’s extension does not change its bytes. This eight-byte fixture represents İstanbul in Windows-1254, so it needs that decoder under the stated input contract. Runnable example:
javascript
const file = new File([
  new Uint8Array([0xDD, 0x73, 0x74, 0x61, 0x6E, 0x62, 0x75, 0x6C])
], "city.csv");
const bytes = await file.arrayBuffer();
console.log(new TextDecoder("windows-1254", { fatal: true }).decode(bytes));
try {
  new TextDecoder("utf-8", { fatal: true }).decode(bytes);
} catch (error) {
  console.log("strict UTF-8 rejected");
}
console.log((await file.text()).startsWith("\uFFFD"));
Expected result:
text
İstanbul
strict UTF-8 rejected
true
Why it works: The leading DD byte is not a valid complete UTF-8 sequence here. Default UTF-8 decoding replaces the malformed portion with a replacement character; fatal mode exposes the mismatch. Successfully decoding with a single-byte encoding does not prove it is the correct encoding. Scope and checks: Run in Node.js 24 with full ICU support or a browser with File and TextDecoder. Confirm Windows-1254 with the producer; do not automatically retry random encodings until one succeeds. After decoding, use a CSV parser for commas, quotes and embedded newlines. Export to UTF-8 if the receiving system requires it. Related tools and guides: Inspect a decoded CSV sample: https://kitforma.com/en/csv-to-json/ Python decoding without data loss: https://kitforma.com/en/community/questions/7aa10000-0000-4000-8000-000000007330/ Primary sources (reviewed 2026-10-08): W3C File API — Blob.text UTF-8 decoding: https://www.w3.org/TR/FileAPI/#dom-blob-text WHATWG Encoding — TextDecoder and encoding labels: https://encoding.spec.whatwg.org/#interface-textdecoder MDN — Blob.text always uses UTF-8: https://developer.mozilla.org/en-US/docs/Web/API/Blob/text

Sources and verification

Sources checked:

This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.

Discussion and community answers

Loading community…
KitForma

What would you like to do?