title: Read binary data with Node.js stream
body: <p>I'm trying to read a binary file with fs <code>createReadStream</code>. Assumed that we know the "misunderstanding" of <code>binary</code> and <code>latin1</code> as value for the <code>encoding</code> option, and that by defaults using <code>toString</code> on the <code>data</code> chunk will use <code>utf-8</code>, I have tried to user a <code>Buffer</code> and buffer concatenation that is the <code>.concat</code> function in this way:</p>
  
  <pre><code>var readStream = fs.createReadStream( graphPath );
                          var data;
                          readStream.on('data', (chunk) =&gt; {
                              var b = new Buffer (chunk.length);
                              if(!data) data = new Buffer (chunk.length);
                              else data = Buffer.concat([data, b]);
                          })  
                          readStream.on('end', () =&gt; {
                              console.log( "type is", typeof (data ) );
                              console.log("read graph %d",data.length);data.buffer);
                          });
  </code></pre>
  
  <p>so that to append the new chunk to the data. In this way the <code>typeof</code> object in <code>data</code> is <code>object</code>, but it seems the encoding it is still not a binary format (i.e. it is not <code>application/octet-stream charset=binary</code> to be clear in terms of content type.)</p>
  
  <p>If I just do <code>data+=chunk</code> the output type will be <code>string</code>.</p>