// Read reads bytes into p.
355637
func (s *Reader) Read(p []byte) (int, error) {
	if s.limiter == nil {
		return s.r.Read(p)
	}
	n, err := s.r.Read(p)
	if err != nil {
		return n, err
	}
	if err := s.limiter.WaitN(s.ctx, n); err != nil {
		return n, err
	}
	return n, nil
}
661460
func (b *Buffer) Read(p []byte) (int, error) {
	version := b.preOp()
	n, err := b.buf.Read(p)
	b.postOp(version)
	return n, err
}
327238
func (s *Stream) Read(p []byte) (int, error) {
	n, err := s.stream.Read(p)
	// TODO: push this down to a lower level for better accuracy.
	if s.conn.swarm.bwc != nil {
		s.conn.swarm.bwc.LogRecvMessage(int64(n))
		s.conn.swarm.bwc.LogRecvMessageStream(int64(n), s.Protocol(), s.Conn().RemotePeer())
	}
	// If we observe an EOF, this stream is now closed for reading.
	// If we're already closed for writing, this stream is now fully closed.
	if err == io.EOF {
		s.state.Lock()
		switch s.state.v {
		case streamCloseWrite:
			s.state.v = streamCloseBoth
			s.remove()
		case streamOpen:
			s.state.v = streamCloseRead
		}
		s.state.Unlock()
	}
	return n, err
}
1308566
func (f FakeFile) Read(p []byte) (n int, err error) {
	return f.Buffer.Read(p)
}
396061
func (ps *ProgressStatus) Read(p []byte) (n int, err error) {
	ps.hook.Read(p)
	return ps.progressBar.Read(p)
}
243141
func (ar *AnsiReader) Read(b []byte) (int, error) {
	return ar.file.Read(b)
}
589625
func (s *Stream) Read(p []byte) (n int, err error) {
	// Don't request a read if there was an error earlier
	if er := s.trReader.(*transportReader).er; er != nil {
		return 0, er
	}
	s.requestRead(len(p))
	return io.ReadFull(s.trReader, p)
}
1122286
func (r *LatinReader) Read(p []byte) (n int, err error) {

	var p2, utf8bytes []byte
	var n2 int
	var e2, e3 error

	p2 = make([]byte, len(p))
	n2, e2 = r.reader.Read(p2)

	if e2 == nil || e2 == io.EOF {

		utf8bytes, e3 = r.converter.Decode(p2[:n2])

		if e3 != nil {
			return 0, e3
		}

		r.buf.Write(utf8bytes) // n always len(input), error always nil

		return r.buf.Read(p)

	} else {
		copy(p, p2)
		n = n2
		err = e2
	}

	return
}
627688
func (gb *Buffer) Read(p []byte) (int, error) {
	gb.Lock()
	defer gb.Unlock()
	return gb.rw.Read(p)
}
652608
func (u readCloser) Read(p []byte) (n int, err error) {
	return u.reader.Read(p)
}
595313
func (l *Locking) Read(p []byte) (n int, err error) {
	l.Lock()
	n, err = l.R.Read(p)
	l.Unlock()
	return
}
116522
func (r *countReader) Read(p []byte) (int, error) {
	n, err := r.fr.Read(p)
	r.off += int64(n)
	return n, err
}
52494
func (s *siphon) Read(p []byte) (int, error) {
	n, err := s.f.Read(p)

	if err == nil {
		return s.buf.Write(p[0:n]) // Write must succeed for Read to succeed
	}

	if err == io.EOF {
		s.d.cacheWithoutLock(s.key, s.buf.Bytes()) // cache may fail
		if closeErr := s.f.Close(); closeErr != nil {
			return n, closeErr // close must succeed for Read to succeed
		}
		return n, err
	}

	return n, err
}
400347
func (b *Reader) Read(p []byte) (n int, err error) {
	n = len(p)
	filled := false
	if n == 0 {
		return 0, b.err
	}
	if b.w == b.r {
		if b.err != nil {
			return 0, b.err
		}
		if n > len(b.buf) {
			// Large read, empty buffer.
			// Allocate a larger buffer for efficiency.
			b.buf = make([]byte, n)
		}
		b.fill()
		filled = true
		if b.w == b.r {
			return 0, b.err
		}
	}

	i := 0
	for i < n {
		rune, size, status := b.decode(b.buf[b.r:b.w])

		if status == STATE_ONLY {
			b.r += size
			continue
		}

		if status == NO_ROOM {
			if b.err != nil {
				rune = 0xfffd
				size = b.w - b.r
				if size == 0 {
					break
				}
				status = INVALID_CHAR
			} else if filled {
				break
			} else {
				b.fill()
				filled = true
				continue
			}
		}

		if i+utf8.RuneLen(rune) > n {
			break
		}

		b.r += size
		if rune < 128 {
			p[i] = byte(rune)
			i++
		} else {
			i += utf8.EncodeRune(p[i:], rune)
		}
	}

	return i, nil
}
521754
func (f *File) Read(p []byte) (n int, err error) {
	origOffset := atomic.LoadInt64(&f.offset)
	readBytes, err := f.fs.config.KBFSOps().Read(
		f.fs.ctx, f.node, p, origOffset)
	if err != nil {
		return 0, err
	}

	if readBytes == 0 {
		return 0, io.EOF
	}

	f.updateOffset(origOffset, readBytes)
	return int(readBytes), nil
}
525391
func (o *LargeObject) Read(p []byte) (int, error) {
	res, err := o.lo.fp.CallFn("loread", []fpArg{fpIntArg(o.fd), fpIntArg(int32(len(p)))})
	if len(res) < len(p) {
		err = io.EOF
	}
	return copy(p, res), err
}
729919
func (r *reader) Read(p []byte) (n int, err error) {
	n, err = r.Reader.Read(p)
	if err != nil {
		return
	}

	err = r.Limiter.Count(n)
	return
}