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

Function readFileTailSync

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

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

Callers 1

Calls 3

readSyncFunction · 0.90
maxMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected