title: byte[] channel usage
body: <p>I am getting a REST command, and want to calculate hash function on it's body.
  To do so I read the body using <code>io.TeeReader(request.Body, &amp;writerToHash)</code> where I pass my own class that implements io.Writer:</p>
  
  <pre><code>func (self *WriterToHash) Write(p []byte) (n int, err error) {
      n=len(p)
      fmt.println("WriterToHash  len=%v, buff=%v", n, p)  //PRINT 1
      self.BodyChannel &lt;- p
      return n, nil
  }
  </code></pre>
  
  <p>The <code>BodyChannel</code> is defined: <code>BodyChannel chan []byte</code></p>
  
  <p>I use this class as follows:</p>
  
  <pre><code>    writerToHash := sisutils.WriterToHash{
          BodyChannel:make(chan []byte, 1024)
      }
      writerToHash.StartListen()
      reqnew, _ := http.NewRequest("PUT", url, io.TeeReader(request.Body, &amp;writerToHash))
  </code></pre>
  
  <p>Listening part:</p>
  
  <pre><code>func (wth *WriterToHash) StartListen() {
      wth.OutChannel = make(chan []byte, 1000)
      go func (self *WriterToHash) {
          done := int64(0)
          h := sha1.New()
          for done &lt; MessageSize{
              buff := &lt;- self.BodyChannel
  
              done += int64(len(buff))
              DPrint(5, "AccamulateSha1 Done=: %v, buff=%v", done, buff)  //PRINT 2
  
              actually_write, err := h.Write(buff)
              if err != nil ||  actually_write != len(buff) {
                  log.Println("Error in sha write:" + err.Error())
                  break
              }
          }
          bs := h.Sum(nil)
          self.OutChannel &lt;- bs
      }(wth)
   }
  </code></pre>
  
  <p>I send messages of 1000 bytes. In debug mode the message is always split in the same way: 1 byte, 999 bytes - I see it using PRINT 1. In this case everythong works fine.
  The problem is that when the message is split to more parts in the Write function. In this case I see in PRINT1:</p>
  
  <p>[first byte] : a</p>
  
  <p>[next ~450 bytes] : b,c,d,...</p>
  
  <p>[last ~550 bytes] : w,x,y,...</p>
  
  <p>but in PRINT 2 I see different picture:</p>
  
  <p>[first byte] : a</p>
  
  <p>[ ~450 bytes but starting where last part starts] : w,x,y...</p>
  
  <p>[last ~550 bytes] : w,x,y,...</p>
  
  <p>I actually get the last past twice but not in the same size.</p>