MCPcopy
hub / github.com/codeaashu/claude-code / readFileTailSync

Function readFileTailSync

src/utils/sessionStorage.ts:2592–2614  ·  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

2590 * string on any error so callers fall through to unconditional behavior.
2591 */
2592function readFileTailSync(fullPath: string): string {
2593 let fd: number | undefined
2594 try {
2595 fd = openSync(fullPath, 'r')
2596 const st = fstatSync(fd)
2597 const tailOffset = Math.max(0, st.size - LITE_READ_BUF_SIZE)
2598 const buf = Buffer.allocUnsafe(
2599 Math.min(LITE_READ_BUF_SIZE, st.size - tailOffset),
2600 )
2601 const bytesRead = readSync(fd, buf, 0, buf.length, tailOffset)
2602 return buf.toString('utf8', 0, bytesRead)
2603 } catch {
2604 return ''
2605 } finally {
2606 if (fd !== undefined) {
2607 try {
2608 closeSync(fd)
2609 } catch {
2610 // closeSync can throw; swallow to preserve return '' contract
2611 }
2612 }
2613 }
2614}
2615/* eslint-enable custom-rules/no-sync-fs */
2616
2617export async function saveCustomTitle(

Callers 1

Calls 3

readSyncFunction · 0.90
maxMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected