code: func (c *ChanReader) Read(out []byte) (int, error) {
  	if c.buffer == nil {
  		return 0, io.EOF
  	}
  	n := copy(out, c.buffer)
  	c.buffer = c.buffer[n:]
  	if len(out) <= len(c.buffer) {
  		return n, nil
  	} else if n > 0 {
  		// We have some data to return, so make the channel read optional
  		select {
  		case p := <-c.input:
  			if p == nil { // Stream was closed
  				c.buffer = nil
  				if n > 0 {
  					return n, nil
  				}
  				return 0, io.EOF
  			}
  			n2 := copy(out[n:], p.Data)
  			c.buffer = p.Data[n2:]
  			return n + n2, nil
  		default:
  			return n, nil
  		}
  	}
  	var p *StreamChunk
  	select {
  	case p = <-c.input:
  	case <-c.interrupt:
  		c.buffer = c.buffer[:0]
  		return n, ErrInterrupted
  	}
  	if p == nil { // Stream was closed
  		c.buffer = nil
  		return 0, io.EOF
  	}
  	n2 := copy(out[n:], p.Data)
  	c.buffer = p.Data[n2:]
  	return n + n2, nil
  }
docs: // Read from the channel into `out`. This will block until data is available,
  // and can be interrupted with a channel using `SetInterrupt()`. If the read
  // was interrupted, `ErrInterrupted` will be returned.