MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / readFileTailSync

Function readFileTailSync

source code/utils/sessionStorage.ts:2594–2616  ·  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

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

Callers 1

Calls 3

readSyncFunction · 0.90
maxMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected