title: Node.js WriteStream synchronous
body: <p>I'm writing a purely synchronous, single threaded command line program in node.js, which needs to write a single binary file, for which I'm using <code>WriteStream</code>. My usage pattern is along the lines of:</p>
  
  <pre><code>var stream = fs.createWriteStream(file)
  stream.write(buf1)
  stream.write(buf2)
  </code></pre>
  
  <p>This seems to work, but the documentation says it's asynchronous and I want to make sure I'm not writing code that works 99% of the time. I don't care exactly when the data gets written as long as it's written in the specified order and no later than when the program exits, and the quantity of data is small so speed and memory consumption are not issues.</p>
  
  <p>I've seen mention of <code>stream.end()</code> but it seems to work without it and I've also seen suggestions that calling it may actually be a bad idea if you're not using callbacks because it might end up getting called before all the data is written.</p>
  
  <p>Is my approach correct (given that I want purely synchronous) or is there anything I need to watch out for?</p>