title: writing/reading binary file in Nim
body: <p>What's the best way to write and read a binary files in Nim? I want to write alternating floats and ints to a binary file and then be able to read the file. To write this binary file in Python I would do something like</p>
  <pre class="lang-py prettyprint-override"><code>import struct
  
  # list of alternating floats and ints
  arr = [0.5, 1, 1.5, 2, 2.5, 3]
  
  # here 'f' is for float and 'i' is for int    
  binStruct = struct.Struct( 'fi' * (len(arr)/2) ) 
  # put it into string format
  packed = binStruct.pack(*tuple(arr))
  
  # open file for writing in binary mode
  with open('/path/to/my/file', 'wb') as fh:
      fh.write(packed)
  </code></pre>
  <p>To read I would do something like</p>
  <pre class="lang-py prettyprint-override"><code>arr = []
  with open('/path/to/my/file', 'rb') as fh:
      data = fh.read()
      for i in range(0, len(data), 8):
          tup = binStruct.unpack('fi', data[i: i + 8])
          arr.append(tup)
  </code></pre>
  <p>In this example, after reading the file, arr would be</p>
  <pre><code>[(0.5, 1), (1.5, 2), (2.5, 3)] 
  </code></pre>
  <p>Looking for similar functionality in Nim.</p>