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

Function readSessionLite

src/utils/sessionStoragePortable.ts:256–282  ·  view source on GitHub ↗
(
  filePath: string,
)

Source from the content-addressed store, hash-verified

254 * Returns null on any error.
255 */
256export async function readSessionLite(
257 filePath: string,
258): Promise<LiteSessionFile | null> {
259 try {
260 const fh = await fsOpen(filePath, 'r')
261 try {
262 const stat = await fh.stat()
263 const buf = Buffer.allocUnsafe(LITE_READ_BUF_SIZE)
264 const headResult = await fh.read(buf, 0, LITE_READ_BUF_SIZE, 0)
265 if (headResult.bytesRead === 0) return null
266
267 const head = buf.toString('utf8', 0, headResult.bytesRead)
268 const tailOffset = Math.max(0, stat.size - LITE_READ_BUF_SIZE)
269 let tail = head
270 if (tailOffset > 0) {
271 const tailResult = await fh.read(buf, 0, LITE_READ_BUF_SIZE, tailOffset)
272 tail = buf.toString('utf8', 0, tailResult.bytesRead)
273 }
274
275 return { mtime: stat.mtime.getTime(), size: stat.size, head, tail }
276 } finally {
277 await fh.close()
278 }
279 } catch {
280 return null
281 }
282}
283
284// ---------------------------------------------------------------------------
285// Path sanitization

Callers 1

readCandidateFunction · 0.85

Calls 4

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

Tested by

no test coverage detected