(bytes: Uint8Array)
| 18 | * ``` |
| 19 | */ |
| 20 | export function decodeUtf8NoBom(bytes: Uint8Array): string { |
| 21 | // Reject UTF-8 BOM (0xEF 0xBB 0xBF) |
| 22 | if (bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) { |
| 23 | throw new EncodingError('UTF-8 BOM detected in Deepnote file - files must be UTF-8 without BOM') |
| 24 | } |
| 25 | |
| 26 | // Validate UTF-8 by decoding with fatal=true |
| 27 | // This will throw if the bytes contain invalid UTF-8 sequences |
| 28 | try { |
| 29 | return new TextDecoder('utf-8', { fatal: true }).decode(bytes) |
| 30 | } catch { |
| 31 | throw new EncodingError('Invalid UTF-8 encoding detected in Deepnote file') |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Validates that a string doesn't start with BOM. |
no outgoing calls