// Read reads a block of data from an inner stream and reports progress
330395
func (b *retryableRequestBody) Read(p []byte) (n int, err error) {
	return b.body.Read(p)
}
707815
func (s *receiveStream) Read(p []byte) (int, error) {
	s.mutex.Lock()
	completed, n, err := s.readImpl(p)
	s.mutex.Unlock()

	if completed {
		s.streamCompleted()
	}
	return n, err
}
478070
func (r *reader) Read(b []byte) (int, error) {
	if len(r.buf) == 0 {
		if r.bufToReturn != nil {
			r.chunkPool.Put(r.bufToReturn)
			r.bufToReturn = nil
		}
		if r.err != nil {
			// Make sure any goroutines are done. Ignore
			// the error since it will just be r.err.
			r.Close()
			return 0, r.err
		}
		resp, ok := <-r.chunkRespc
		if !ok {
			glog.Fatal("chunkRespc channel has been closed without a final error")
		}
		if resp.err != nil {
			r.err = resp.err
		}
		r.buf = resp.chunk
		r.bufToReturn = resp.chunk[:cap(resp.chunk)]
	}
	n := copy(b, r.buf)
	r.buf = r.buf[n:]
	if len(r.buf) == 0 {
		return n, r.err
	}
	return n, nil
}
910265
func (p *Part) Read(d []byte) (n int, err error) {
	return p.r.Read(d)
}
880965
func (ws *bytesReadWriteSeeker) Read(b []byte) (int, error) {
	if ws.i >= int64(len(ws.buf)) {
		return 0, io.EOF
	}
	n := copy(b, ws.buf[ws.i:])
	ws.i += int64(n)
	return n, nil
}
748964
func (ar *Reader) Read(b []byte) (n int, err error) {
	if ar.nb == 0 {
		// file consumed
		return 0, io.EOF
	}

	if int64(len(b)) > ar.nb {
		b = b[0:ar.nb]
	}
	n, err = ar.r.Read(b)
	ar.nb -= int64(n)

	if err == io.EOF && ar.nb > 0 {
		err = io.ErrUnexpectedEOF
	}
	ar.err = err
	return
}
121239
func (u *ProgressTrackingClient) Read(b []byte) (read int, err error) {
	defer func() {
		if err := u.client.Call("Ui"+u.id+".Add", read, new(interface{})); err != nil {
			log.Printf("Error in ProgressTrackingClient.Read RPC call: %s", err)
		}
	}()
	return u.stream.Read(b)
}
107805
func (r *ByteReader) Read(b []byte) (n int, err error) {
	if len(b) == 0 {
		return 0, nil
	}
	if r.off >= len(r.buf) {
		return 0, io.EOF
	}
	n = copy(b, r.buf[r.off:])
	r.off += n
	return
}
926016
func (r *Reader) Read(p []byte) (n int, err error) {
	p = p[:r.Limit(len(p), r.limit, r.block)]
	if len(p) > 0 {
		n, err = r.IO(r.Reader.Read(p))
	}
	return
}
261246
func (r *WALSegmentReader) Read() (WALEntry, error) {
	if r.err != nil {
		return nil, r.err
	}
	return r.entry, nil
}
92583
func (s *Stream) Read(b []byte) (n int, err error) {
	if len(b) == 0 {
		select {
		case <-s.die:
			return 0, errors.New(errBrokenPipe)
		default:
			return 0, nil
		}
	}

	var deadline <-chan time.Time
	if d, ok := s.readDeadline.Load().(time.Time); ok && !d.IsZero() {
		timer := time.NewTimer(time.Until(d))
		defer timer.Stop()
		deadline = timer.C
	}

READ:
	s.bufferLock.Lock()
	if len(s.buffers) > 0 {
		n = copy(b, s.buffers[0])
		s.buffers[0] = s.buffers[0][n:]
		if len(s.buffers[0]) == 0 {
			s.buffers[0] = nil
			s.buffers = s.buffers[1:]
		}
	}
	s.bufferLock.Unlock()

	if n > 0 {
		s.sess.returnTokens(n)
		return n, nil
	} else if atomic.LoadInt32(&s.rstflag) == 1 {
		_ = s.Close()
		return 0, io.EOF
	}

	select {
	case <-s.chReadEvent:
		goto READ
	case <-deadline:
		return n, errTimeout
	case <-s.die:
		return 0, errors.New(errBrokenPipe)
	}
}
982738
func (ff *FileFragment) Read(b []byte) (n int, err error) {
	offset, err := ff.file.Seek(0, io.SeekCurrent)
	if err != nil {
		return 0, err
	}

	if int64(len(b)) > ff.endLoc-offset {
		n, err := ff.file.Read(b[:ff.endLoc-offset])
		if int64(n) == ff.endLoc-offset {
			return n, io.EOF
		}
		return n, err
	}
	return ff.file.Read(b)
}
1104834
func (r *reader) Read(b []byte) (int, error) {
	r.Do(term.ClearAll)
	n, err := r.ReadCloser.Read(b)
	r.written += n
	r.p.ValueInt(r.written)
	r.render(term.CenterLine(r.p.String()))
	return n, err
}
1246714
func (r *Reader) Read() ([]byte, error) {
	r.Lock()
	defer r.Unlock()

	if _, err := io.ReadFull(r.r, r.buff[:]); err != nil {
		return nil, err
	}

	length := int64(binary.BigEndian.Uint32(r.buff[:]))
	if length < _fastPathFrameSize {
		return r.readFastPath(length)
	}

	var buff bytes.Buffer
	_, err := io.CopyN(&buff, r.r, length)
	if err != nil {
		return nil, err
	}

	return buff.Bytes(), nil
}
561344
func (stream *OdbReadStream) Read(data []byte) (int, error) {
	header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
	ptr := (*C.char)(unsafe.Pointer(header.Data))
	size := C.size_t(header.Cap)

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_odb_stream_read(stream.ptr, ptr, size)
	runtime.KeepAlive(stream)
	if ret < 0 {
		return 0, MakeGitError(ret)
	}
	if ret == 0 {
		return 0, io.EOF
	}

	header.Len = int(ret)

	return len(data), nil
}
564432
func (r *reader) Read(b []byte) (int, error) {
	n, err := r.Reader.Read(b)
	r.read += int64(n)
	return n, err
}
727846
func (d Decoder) read() (*bytes.Buffer, error) {
	output := &bytes.Buffer{}
	for {
		lengthBytes := make([]byte, 2)
		if numRead, err := io.ReadFull(d.r, lengthBytes); numRead != 2 {
			return nil, errors.Wrap(err, "Couldn't read expected bytes for message length. Read: %d Expected: 2.", numRead)
		}

		// Chunk header contains length of current message
		messageLen := binary.BigEndian.Uint16(lengthBytes)
		if messageLen == 0 {
			// If the length is 0, the chunk is done.
			return output, nil
		}

		data, err := d.readData(messageLen)
		if err != nil {
			return output, errors.Wrap(err, "An error occurred reading message data")
		}

		numWritten, err := output.Write(data)
		if numWritten < len(data) {
			return output, errors.New("Didn't write full data on output. Expected: %d Wrote: %d", len(data), numWritten)
		} else if err != nil {
			return output, errors.Wrap(err, "Error writing data to output")
		}
	}
}