MCPcopy
hub / github.com/claude-code-best/claude-code / detectFileEncoding

Function detectFileEncoding

src/utils/file.ts:100–118  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

98}
99
100export function detectFileEncoding(filePath: string): BufferEncoding {
101 try {
102 const fs = getFsImplementation()
103 const { resolvedPath } = safeResolvePath(fs, filePath)
104 return detectEncodingForResolvedPath(resolvedPath)
105 } catch (error) {
106 if (isFsInaccessible(error)) {
107 logForDebugging(
108 `detectFileEncoding failed for expected reason: ${error.code}`,
109 {
110 level: 'debug',
111 },
112 )
113 } else {
114 logError(error)
115 }
116 return 'utf8'
117 }
118}
119
120export function detectLineEndings(
121 filePath: string,

Callers 2

applySedEditFunction · 0.85
readFileMethod · 0.85

Calls 6

getFsImplementationFunction · 0.85
safeResolvePathFunction · 0.85
isFsInaccessibleFunction · 0.85
logForDebuggingFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected