lionsoul2014/ip2region · error · Error
incomplete read: read bytes should be ${buff.length}
Error message
incomplete read: read bytes should be ${buff.length} What it means
A sentinel I/O integrity error raised in the JS searcher's read() when fs.readSync returns fewer bytes than the requested buffer length while loading a header, vector-index row, segment index, or region data from the xdb file. It almost always means the file was truncated, corrupted, or concurrently replaced after the searcher was opened.
Source
Thrown at binding/javascript/searcher.js:122
const region = Buffer.alloc(dLen);
this.read(dPtr, region);
return region.toString('utf-8');
}
read(offset, buff, stats) {
// check the in-memory buffer first
if (this.cBuffer != null) {
this.cBuffer.copy(buff, 0, offset, offset + buff.length);
return;
}
// increase the io counts
this.ioCount++;
// read the data
let rBytes = fs.readSync(this.handle, buff, 0, buff.length, offset);
if (rBytes != buff.length) {
throw new Error(`incomplete read: read bytes should be ${buff.length}`);
}
}
// close the searcher
close() {
if (this.handle != null) {
fs.close(this.handle);
}
}
toString() {
const vn = this.version.name;
const vi = this.vectorIndex == null ? 'null' : this.vectorIndex.length;
const cf = this.cBuffer == null ? 'null' : this.cBuffer.length;
return `{"version": ${vn}, "dbPath": ${this.dbPath}, "handle": ${this.handle}, "vectorIndex": ${vi} "cBuffer": ${cf}}`;
}
}
View on GitHub (pinned to c1a1fc7d59)
Solutions
- Verify the xdb file integrity (re-download or re-generate it with the maker) and compare its size against the header's end pointer
- Reopen the searcher on a known-good xdb file; do not keep a handle to a file that can be swapped underneath
- If loading the whole file, prefer the content-buffer constructor so partial reads from a shrinking file cannot occur mid-search
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at binding/javascript/searcher.js:122 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/f572e44cacb1e932.
Report an issue: GitHub.