MCPcopy Create free account
hub / github.com/deepnote/deepnote / decodeUtf8NoBom

Function decodeUtf8NoBom

packages/blocks/src/deepnote-file/parse-yaml.ts:20–33  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

18 * ```
19 */
20export 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.

Callers 12

diffDeepnoteFilesFunction · 0.90
validateDeepnoteFileFunction · 0.90
inspectDeepnoteFileFunction · 0.90
catDeepnoteFileFunction · 0.90
parseIntegrationsFileFunction · 0.90
parse-yaml.test.tsFile · 0.90
loadRunnableFileFunction · 0.90
resolveAndComposeInitFunction · 0.90
handleValidateFunction · 0.90
runFileMethod · 0.90
loadExampleFileFunction · 0.90
loadFixtureFunction · 0.90

Calls

no outgoing calls

Tested by 2

loadExampleFileFunction · 0.72
loadFixtureFunction · 0.72