title: Go. Writing []byte to file results in zero byte file
body: <p>I try to serialize a structured data to file. I looked through some examples and made such construction:</p>
  
  <pre><code>func (order Order) Serialize(folder string) {
      b := bytes.Buffer{}
      e := gob.NewEncoder(&amp;b)
      err := e.Encode(order)
      if err != nil { panic(err) }
  
      os.MkdirAll(folder, 0777)
      file, err := os.Create(folder + order.Id)
      if err != nil {  panic(err) }
      defer file.Close()
  
  
      writer := bufio.NewWriter(file)
      n, err := writer.Write(b.Bytes())
  
      fmt.Println(n)
  
      if err != nil {
          panic(err)
      }
  }
  </code></pre>
  
  <p><code>Serialize</code> is a method serializing its object to file called by it's <em>id</em> property. I looked through debugger - byte buffer contains data before writing. I mean object is fully initialized. Even <code>n</code> variable representing quantity of written bytes is more than a thousand - the file shouldn't be empty at all. The file is created but it is totally empty. What's wrong?</p>