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

Function tailFile

source code/utils/fsOperations.ts:684–716  ·  view source on GitHub ↗
(
  path: string,
  maxBytes: number,
)

Source from the content-addressed store, hash-verified

682 * Returns the whole file if it's smaller than maxBytes.
683 */
684export async function tailFile(
685 path: string,
686 maxBytes: number,
687): Promise<ReadFileRangeResult> {
688 await using fh = await open(path, 'r')
689 const size = (await fh.stat()).size
690 if (size === 0) {
691 return { content: '', bytesRead: 0, bytesTotal: 0 }
692 }
693 const offset = Math.max(0, size - maxBytes)
694 const bytesToRead = size - offset
695 const buffer = Buffer.allocUnsafe(bytesToRead)
696
697 let totalRead = 0
698 while (totalRead < bytesToRead) {
699 const { bytesRead } = await fh.read(
700 buffer,
701 totalRead,
702 bytesToRead - totalRead,
703 offset + totalRead,
704 )
705 if (bytesRead === 0) {
706 break
707 }
708 totalRead += bytesRead
709 }
710
711 return {
712 content: buffer.toString('utf8', 0, totalRead),
713 bytesRead: totalRead,
714 bytesTotal: size,
715 }
716}
717
718/**
719 * Async generator that yields lines from a file in reverse order.

Callers 4

getTaskOutputFunction · 0.85
getTaskOutputFunction · 0.85
#tickMethod · 0.85
startStallWatchdogFunction · 0.85

Calls 4

openFunction · 0.85
maxMethod · 0.80
toStringMethod · 0.65
readMethod · 0.45

Tested by

no test coverage detected