Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Cannot read large files #1094

Closed
shinout opened this issue May 23, 2011 · 0 comments
Closed

Cannot read large files #1094

shinout opened this issue May 23, 2011 · 0 comments
Labels

Comments

@shinout
Copy link

shinout commented May 23, 2011

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants