Open way modify

This commit is contained in:
Eli-Class
2026-02-03 06:39:46 +00:00
parent 9eb4b17b34
commit 00635bdb67
7 changed files with 61 additions and 21 deletions

View File

@@ -7,14 +7,14 @@ export class IndexReader {
private buffer: Buffer | null = null;
private header: IndexHeader | null = null;
readonly path: string;
private path: string | null = null;
constructor(path: string) {
this.path = path;
constructor() {
}
open(): void {
open(idxFilePath: string): void {
// Read entire file into buffer (simpler than mmap for read-only access)
this.path = idxFilePath;
this.buffer = fs.readFileSync(this.path);
this.header = IndexProtocol.readHeader(this.buffer);
}
@@ -24,6 +24,11 @@ export class IndexReader {
return this.header;
}
getFlags(): number {
if (!this.header) throw new Error('Index file not opened');
return this.header.flags;
}
getEntry(index: number): IndexEntry | null {
if (!this.buffer || !this.header) throw new Error('Index file not opened');
if (index < 0 || index >= this.header.entryCount) return null;