MCPcopy Create free account
hub / github.com/Noumena-Network/code / readFileTailSync

Function readFileTailSync

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

2770 * string on any error so callers fall through to unconditional behavior.
2771 */
2772function readFileTailSync(fullPath: string): string {
2773 let fd: number | undefined
2774 try {
2775 fd = openSync(fullPath, 'r')
2776 const st = fstatSync(fd)
2777 const tailOffset = Math.max(0, st.size - LITE_READ_BUF_SIZE)
2778 const buf = Buffer.allocUnsafe(
2779 Math.min(LITE_READ_BUF_SIZE, st.size - tailOffset),
2780 )
2781 const bytesRead = readSync(fd, buf, 0, buf.length, tailOffset)
2782 return buf.toString('utf8', 0, bytesRead)
2783 } catch {
2784 return ''
2785 } finally {
2786 if (fd !== undefined) {
2787 try {
2788 closeSync(fd)
2789 } catch {
2790 // closeSync can throw; swallow to preserve return '' contract
2791 }
2792 }
2793 }
2794}
2795/* eslint-enable custom-rules/no-sync-fs */
2796
2797export async function saveCustomTitle(

Callers 1

Calls 3

readSyncFunction · 0.90
maxMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected