js-mdict
Version:
mdict (*.mdx, *.mdd) file reader. Licensed under AGPL-3.0 for better community cooperation and commercial value protection.
34 lines • 1.04 kB
JavaScript
import { closeSync, openSync, readSync } from 'node:fs';
export class FileScanner {
constructor(filepath) {
this.filepath = filepath;
this.offset = 0;
this.fd = openSync(filepath, 'r');
}
close() {
if (this.fd == 0) {
return;
}
closeSync(this.fd);
}
readBuffer(offset, length) {
const buffer = new Uint8Array(length);
const readedLen = readSync(this.fd, buffer, {
offset: 0, // here offset means the data will write into buffer's offset
length: length,
position: offset, // here the offset is the file's start read position
});
return buffer.slice(0, readedLen);
}
readNumber(offset, length) {
const buffer = new ArrayBuffer(length);
const dataView = new DataView(buffer);
readSync(this.fd, dataView, {
length: length,
position: offset,
offset: 0,
});
return dataView;
}
}
//# sourceMappingURL=scanner.js.map