( filePath: string, )
| 254 | * Returns null on any error. |
| 255 | */ |
| 256 | export 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 |
no test coverage detected