code: func (w *syncFileWriter) Write(buf []byte) (n int, err error) {
  	written := 0
  
  	// If buf > 64k we'll have to send multiple chunks.
  	// TODO Refactor this into something that can coalesce smaller writes into a single chukn.
  	for len(buf) > 0 {
  		// Writes < 64k have a one-to-one mapping to chunks.
  		// If buffer is larger than the max, we'll return the max size and leave it up to the
  		// caller to handle correctly.
  		partialBuf := buf
  		if len(partialBuf) > wire.SyncMaxChunkSize {
  			partialBuf = partialBuf[:wire.SyncMaxChunkSize]
  		}
  
  		if err := w.sender.SendOctetString(wire.StatusSyncData); err != nil {
  			return written, err
  		}
  		if err := w.sender.SendBytes(partialBuf); err != nil {
  			return written, err
  		}
  
  		written += len(partialBuf)
  		buf = buf[len(partialBuf):]
  	}
  
  	return written, nil
  }
docs: // Write writes the min of (len(buf), 64k).