Node: trying to stream an Excel file and pass the buffer to 'xlsx' library
<p>I'm using the node.js package 'xlsx' to read an excel file. Reading a file from the file system synchronously works fine, but streaming is a bit tricky. ( The file is served remotely and I can only receive it as a stream. ) Local streamed files produce the same problem, so it's easy to reproduce.</p>

<p>I've followed the examples here: <a href="https://www.npmjs.com/package/xlsx" rel="nofollow">https://www.npmjs.com/package/xlsx</a> but get "end of data reached" or "unsupported file" depending on approach. </p>

<pre><code>const XLSX = require('xlsx');
const fs = require('fs');

const stream = fs.createReadStream('sample.xlsx');


// This function returns Error: Unsupported file 48

documentedExample = function(){
  var arr = new Array();

  stream.on('data', function( arraybuffer ){
    var data = new Uint8Array(arraybuffer);
    for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
  });
  stream.on('end', function(){
    var bstr = arr.join("");
    var workbook = XLSX.read(bstr, {type:"binary"});

  });
}


// This function returns Error: End of data reached (data length = 75589, asked index = 77632). Corrupted zip ?

alternateExample = function(){
  var bufferArray = [];
  stream.on('data', function( thisChunk ){
    bufferArray.push( thisChunk );
  });
  stream.on('end', function(){
    var excelDataBuffer = bufferArray.join("");
    excelDataBuffer = excelDataBuffer.toString();
    var workbook = XLSX.read(excelDataBuffer, {type:"binary"});
  });
}
</code></pre>

<p>What would be the correct way to reassemble an xlsx binary for local use?</p>