MCPcopy Index your code
hub / github.com/codeaashu/claude-code / tailFile

Function tailFile

src/utils/fsOperations.ts:682–714  ·  view source on GitHub ↗
(
  path: string,
  maxBytes: number,
)

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected