MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / readFileTailSync

Function readFileTailSync

src/utils/sessionStorage.ts:2631–2653  ·  view source on GitHub ↗

* Sync tail read for reAppendSessionMetadata's external-writer check. * fstat on the already-open fd (no extra path lookup); reads the same * LITE_READ_BUF_SIZE window that readLiteMetadata scans. Returns empty * string on any error so callers fall through to unconditional behavior.

(fullPath: string)

Source from the content-addressed store, hash-verified

2629 * string on any error so callers fall through to unconditional behavior.
2630 */
2631function readFileTailSync(fullPath: string): string {
2632 let fd: number | undefined
2633 try {
2634 fd = openSync(fullPath, 'r')
2635 const st = fstatSync(fd)
2636 const tailOffset = Math.max(0, st.size - LITE_READ_BUF_SIZE)
2637 const buf = Buffer.allocUnsafe(
2638 Math.min(LITE_READ_BUF_SIZE, st.size - tailOffset),
2639 )
2640 const bytesRead = readSync(fd, buf, 0, buf.length, tailOffset)
2641 return buf.toString('utf8', 0, bytesRead)
2642 } catch {
2643 return ''
2644 } finally {
2645 if (fd !== undefined) {
2646 try {
2647 closeSync(fd)
2648 } catch {
2649 // closeSync can throw; swallow to preserve return '' contract
2650 }
2651 }
2652 }
2653}
2654/* eslint-enable custom-rules/no-sync-fs */
2655
2656export async function saveCustomTitle(

Callers 1

Calls 3

readSyncFunction · 0.90
maxMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected