satish wanjari
satish wanjari

Reputation: 291

File size (6003804160) is greater than possible Buffer: 2147483647 in node

While trying to read the file size is 5GB in node.js I got this error:

error: RangeError [ERR_FS_FILE_TOO_LARGE]: File size (6003804160) is greater than possible Buffer: 2147483647 bytes

fs.readFile(tempfile, "utf8", function(err, filebuffer) {
      console.log(err,"filebuffer " ,filebuffer);
})

Please suggest the solution.

Upvotes: 3

Views: 5840

Answers (1)

Matus Dubrava
Matus Dubrava

Reputation: 14462

2147483647 bytes is the maximum size a Buffer can have in NodeJS. Note that this operation will load all the contents of the file into memory at once. Are you sure that you want to push 5gb of data into your memory?

If you need to read files larger than that, you will need to use fs.createReadStream function instead of fs.readFile. fs.createReadStream allow you to "split" the file into small(er) chunks and read one chunk at a time.

Upvotes: 6

Related Questions