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

Function readFileSyncWithMetadata

src/utils/fileRead.ts:75–98  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

73 * readSync(4KB).
74 */
75export function readFileSyncWithMetadata(filePath: string): {
76 content: string
77 encoding: BufferEncoding
78 lineEndings: LineEndingType
79} {
80 const fs = getFsImplementation()
81 const { resolvedPath, isSymlink } = safeResolvePath(fs, filePath)
82
83 if (isSymlink) {
84 logForDebugging(`Reading through symlink: ${filePath} -> ${resolvedPath}`)
85 }
86
87 const encoding = detectEncodingForResolvedPath(resolvedPath)
88 const raw = fs.readFileSync(resolvedPath, { encoding })
89 // Detect line endings from the raw head before CRLF normalization erases
90 // the distinction. 4096 code units is ≥ detectLineEndings's 4096-byte
91 // readSync sample (line endings are ASCII, so the unit mismatch is moot).
92 const lineEndings = detectLineEndingsForString(raw.slice(0, 4096))
93 return {
94 content: raw.replaceAll('\r\n', '\n'),
95 encoding,
96 lineEndings,
97 }
98}
99
100export function readFileSync(filePath: string): string {
101 return readFileSyncWithMetadata(filePath).content

Callers 6

validateInputFunction · 0.85
callFunction · 0.85
readFileForEditFunction · 0.85
callFunction · 0.85
readFileSyncFunction · 0.85

Calls 5

getFsImplementationFunction · 0.85
safeResolvePathFunction · 0.85
logForDebuggingFunction · 0.70

Tested by

no test coverage detected