title: Synchronously read file and convert to byte-array
body: <p>I'm using <code>Node.js</code> to gzip some files and output their raw byte array to a file.</p>
  
  <p>For example:</p>
  
  <p><strong>test.txt:</strong></p>
  
  <pre><code>1234
  </code></pre>
  
  <blockquote>
    <p>text.txt > test.txt.gz</p>
    
    <p>test.txt.gz to byte array > array.txt</p>
  </blockquote>
  
  <p><strong>array.txt:</strong></p>
  
  <pre><code>{0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e}
  </code></pre>
  
  <p><br>
  I couldn't seem to find any other questions on converting files to byte-arrays, or any npm packages. I have attempted to manually <code>fs.readFileSync</code> a file and use it in a function, but due to the special characters and encoding it failed.</p>
  
  <p><strong>How can I convert a file to a byte array in Node.js natively or using a package?</strong></p>