MCPcopy
hub / github.com/codeaashu/claude-code / readHeadAndTail

Function readHeadAndTail

src/utils/sessionStoragePortable.ts:215–242  ·  view source on GitHub ↗
(
  filePath: string,
  fileSize: number,
  buf: Buffer,
)

Source from the content-addressed store, hash-verified

213 * Returns `{ head: '', tail: '' }` on any error.
214 */
215export async function readHeadAndTail(
216 filePath: string,
217 fileSize: number,
218 buf: Buffer,
219): Promise<{ head: string; tail: string }> {
220 try {
221 const fh = await fsOpen(filePath, 'r')
222 try {
223 const headResult = await fh.read(buf, 0, LITE_READ_BUF_SIZE, 0)
224 if (headResult.bytesRead === 0) return { head: '', tail: '' }
225
226 const head = buf.toString('utf8', 0, headResult.bytesRead)
227
228 const tailOffset = Math.max(0, fileSize - LITE_READ_BUF_SIZE)
229 let tail = head
230 if (tailOffset > 0) {
231 const tailResult = await fh.read(buf, 0, LITE_READ_BUF_SIZE, tailOffset)
232 tail = buf.toString('utf8', 0, tailResult.bytesRead)
233 }
234
235 return { head, tail }
236 } finally {
237 await fh.close()
238 }
239 } catch {
240 return { head: '', tail: '' }
241 }
242}
243
244export type LiteSessionFile = {
245 mtime: number

Callers 1

readLiteMetadataFunction · 0.85

Calls 4

maxMethod · 0.80
readMethod · 0.65
toStringMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected