title: How to create valid Avro format file nodejs
body: <p>I'm trying to create a valid avro file for uploading to google-bigquery.</p>
  
  <pre><code>var avro = require('node-avro-io').DataFile.AvroFile();
  var schema = {
              "name": "data",
              "type": "record",
              "fields": [
                  {"name":"key","type": "string"},
                  {"name":"value","type": "string"},
                  {"name":"flag","type": "boolean"},
                  {"name":"subrecord","type":"record","fields":[
                      {"name":"key","type":"string"},
                      {"name":"value","type":["string","int","null"]}
                  ]}
              ]
  };
  var writer = avro.open("myAvroFile.avro", schema, { flags: 'w' , codec: 'deflate'});
  writer
      .append({ key:"john", value:"hive", flag: true, subrecord: { key: "preference", value: 2}})
      .append({ key:"eric", value:"lola", flag: true, subrecord: { key: "postcode", value: null}})
      .end({ key:"fred", value:"wonka", flag: false, subrecord: { key: "city", value: "michigan"}});
  </code></pre>
  
  <p>and here is  <code>myAvroFile.avro</code>:</p>
  
  <pre><code>Obj�avro.codec�deflate�avro.schema�{"name":"data","type":"record","fields":[{"name":"key","type":"string"},{"name":"value","type":"string"},{"name":"flag","type":"boolean"},{"name":"subrecord","type":"record","fields":[{"name":"key","type":"string"},{"name":"value","type":["string","int","null"]}]}]} �3�ä0�x���A� @0O� )�T�%H4��:�*Uy�&gt;P0��%�05k��n�d�T�������\����I�3�ä0�x�
  </code></pre>
  
  <p>but when I try uploading it to big-query it fails: </p>
  
  <pre><code>The Apache Avro library failed to parse file
  </code></pre>
  
  <p>when I try uploading the unzipped avro fli from the following link I succeed. <code>https://cloud.google.com/bigquery/docs/yob1900.avro.zip</code></p>
  
  <p>any reason why <code>myAvroFile.avro</code> isn't valid?
  how do I use <code>node-avro-io</code> library to create valid avro files?</p>