MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / readSessionLite

Function readSessionLite

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

Source from the content-addressed store, hash-verified

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

Callers 1

readCandidateFunction · 0.85

Calls 4

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

Tested by

no test coverage detected