NodeJS - Downloading from Google Drive
<p>I have this piece of code in order to download files from <code>Google Drive</code>:</p>

<pre><code>function downloadDrive(fileId, callback) {
  var fileExt = fileId.split(".");
  var file = Date.now() + "." + fileExt[fileExt.length - 1];
  var dest = fs.createWriteStream("./files/"+file);
  service.files.get({
    auth: oauth2Client,
    fileId: fileExt[0],
    alt: "media"
  })
  .on("finish", function() {
    callback(file);
  })
  .on("error", function(err) {
    console.log("Error during download", err);
  })
  .pipe(dest);
}
</code></pre>

<p>It works very well on small files ~500Mb. However, when trying to download a quite a big gzip file ~3Gb, it throws the following error.</p>

<pre><code>buffer.js:23
  const ui8 = new Uint8Array(size);
              ^

RangeError: Invalid typed array length
    at new Uint8Array (native)
    at createBuffer (buffer.js:23:15)
    at allocate (buffer.js:98:12)
    at new Buffer (buffer.js:53:12)
    at Function.Buffer.concat (buffer.js:225:16)
    at BufferList.copy (/Synology/server_Metagenomics/server/node_modules/googleapis/node_modules/google-auth-library/node_modules/request/node_modules/bl/bl.js:124:21)
    at BufferList.slice (/Synology/server_Metagenomics/server/node_modules/googleapis/node_modules/google-auth-library/node_modules/request/node_modules/bl/bl.js:99:15)
    at BufferList.toString (/Synology/server_Metagenomics/server/node_modules/googleapis/node_modules/google-auth-library/node_modules/request/node_modules/bl/bl.js:166:15)
    at Request.&lt;anonymous&gt; (/Synology/server_Metagenomics/server/node_modules/googleapis/node_modules/google-auth-library/node_modules/request/request.js:1035:36)
    at emitOne (events.js:82:20)
    at Request.emit (events.js:169:7)
</code></pre>

<p>I didn't find a lot of information about it. What is going on?</p>