This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Closed
Description
The code below doen't work correctly.
const fs = require('fs');
var fd = fs.openSync('largefile.txt', 'r'); // largefile.txt is a very large file.
var data = fs.readSync(fd, 100, 5294756210);
Then, the variable 'data' contains data from the beginning of the file.
A similar situation also happens in using fs.createReadStream().
I've also checked the largest start position we can put,
using code like below.
var start = 529475621; // working correctly
var limit = 5294756210; // not working correctly
var count = 0;
while (count < 100000) {
var data = fs.readSync(fd, 100, r);
var invalid = (data[0].substr(0,10) == 'start chars');
if (invalid) {
r -= Math.floor((r - start)/2);
}
else {
r += Math.floor((limit - r)/2);
}
count++;
console.log(count, r, data[0].substr(0,10));
}
then I found that if the variable [r] is the same value,
the variable [data] could change with time.