// eof closes the buffer. Reads from the buffer once all
// the data has been consumed will receive os.EOF.
353962
func (b *buffer) eof() error {
	b.Cond.L.Lock()
	b.closed = true
	b.Cond.Signal()
	b.Cond.L.Unlock()
	return nil
}
146368
func (r *NBReader) Read(buffer []byte) (int, error) {
	var (
		remaining   time.Duration
		nextTimeout time.Duration
		start       = time.Now()
		lastStart   = time.Now()
	)

	if len(buffer) <= r.buffer.Len() {
		ret, _ := r.buffer.Read(buffer)
		return ret, nil
	}

	if r.isEOF {
		return r.buffer.Read(buffer)
	}

	for r.buffer.Len() < len(buffer) {
		lastStart = time.Now()
		remaining = r.forceTimeout - time.Now().Sub(start)
		if r.chunkTimeout == 0 || r.chunkTimeout > remaining {
			nextTimeout = remaining
		} else {
			nextTimeout = r.chunkTimeout
		}
		_, err := r.readWithTimeout(r.buffer, nextTimeout)
		duration := time.Now().Sub(lastStart)
		if err == errTimeout {
			if duration >= r.chunkTimeout {
				break
			}
		}
		if err == io.EOF {
			r.isEOF = true
			break
		}
		if time.Now().Sub(start) >= r.forceTimeout {
			break
		}
	}
	ret, _ := r.buffer.Read(buffer)
	return ret, nil
}
1071442
func (body *Body) Buffer() *bytes.Buffer {
	var b bytes.Buffer
	if body.Reader == nil {
		return &b
	}

	b.ReadFrom(body.Reader)
	_, err := body.Reader.(io.Seeker).Seek(0, 0)
	if err != nil {
		log.Fatal(err)
	}
	return &b
}
892587
func noeof64(n int64, err error) (int64, error) {
	if err == io.EOF {
		return n, io.ErrUnexpectedEOF
	}
	return n, err
}
285262
func (sc scanCloser) Buffer(buf []byte, max int) {
	sc.scanner.Buffer(buf, max)
}
264256
func noEOF(e error) error {
	if e == io.EOF {
		return io.ErrUnexpectedEOF
	}
	return e
}
160572
func (buf *Buffer) Close() {
	zero(buf.buf, len(buf.buf))
	buf.buf = nil
}
1197206
func tryReadFull(r io.Reader, b []byte) (n int, err error) {
	for len(b) > n && err == nil {
		var nn int
		nn, err = r.Read(b[n:])
		n += nn
	}
	if len(b) == n && err == io.EOF {
		err = nil
	}
	return n, err
}
373686
func CloseBody(rc io.ReadCloser) {
	// Go 1.2 pseudo-bug: the NewDecoder(res.Body).Decode never
	// sees an EOF, so we have to do this 0-byte copy here to
	// force the http Transport to see its own EOF and recycle the
	// connection. In Go 1.1 at least, the Close would cause it to
	// read to EOF and recycle the connection, but in Go 1.2, a
	// Close before EOF kills the underlying TCP connection.
	//
	// Will hopefully be fixed in Go 1.3, at least for bodies with
	// Content-Length.  Or maybe Go 1.3's Close itself would look
	// to see if we're at EOF even if it hasn't been Read.

	// TODO: use a bytepool package somewhere for this byte?
	// Justification for 3 byte reads: two for up to "\r\n" after
	// a JSON/XML document, and then 1 to see EOF if we haven't yet.
	buf := make([]byte, 1)
	for i := 0; i < 3; i++ {
		_, err := rc.Read(buf)
		if err != nil {
			break
		}
	}
	rc.Close()
}
1014379
func (i *Input) Read(p []byte) (n int, err error) {
	i.Mutex.Lock()
	defer i.Mutex.Unlock()
	if i.src == nil {
		return 0, io.EOF
	}
	return i.src.Read(p)
}
335758
func (c *Client) Close() {
	if c.file != nil && c.file != os.Stdout {
		c.file.Close()
	}
}
75645
func EOF(err error) bool {
	if err == io.EOF {
		return true
	}

	if strings.Contains(err.Error(), "closed") {
		return true
	}

	if strings.Contains(err.Error(), "reset by peer") {
		return true
	}

	return false
}
570035
func (r *reader) read() (ch rune, pos Pos) {
	// If we have unread characters then read them off the buffer first.
	if r.n > 0 {
		r.n--
		return r.curr()
	}

	// Read next rune from underlying reader.
	// Any error (including io.EOF) should return as EOF.
	ch, _, err := r.r.ReadRune()
	if err != nil {
		ch = eof
	} else if ch == '\r' {
		if ch, _, err := r.r.ReadRune(); err != nil {
			// nop
		} else if ch != '\n' {
			_ = r.r.UnreadRune()
		}
		ch = '\n'
	}

	// Save character and position to the buffer.
	r.i = (r.i + 1) % len(r.buf)
	buf := &r.buf[r.i]
	buf.ch, buf.pos = ch, r.pos

	// Update position.
	// Only count EOF once.
	if ch == '\n' {
		r.pos.Line++
		r.pos.Char = 0
	} else if !r.eof {
		r.pos.Char++
	}

	// Mark the reader as EOF.
	// This is used so we don't double count EOF characters.
	if ch == eof {
		r.eof = true
	}

	return r.curr()
}
1359657
func (s *Scanner) Close() error {
	buf := byteSlicePool.Get().([]byte)
	_, err := io.CopyBuffer(stdioutil.Discard, s.r, buf)
	byteSlicePool.Put(buf)
	return err
}
298137
func (z *reader) Close() error {
	if z.err != nil && z.err != io.EOF {
		return z.err
	}
	z.err = z.decompressor.Close()
	return z.err
}
1266362
func (s *Scanner) read() {
	if s.eof {
		return
	}

	r, w, err := s.r.ReadRune()
	if err != nil {
		s.fatalError(err)
		return
	}

	s.cur = r
	s.cpos.Off += s.cw
	s.cw = w

	// newline is '\n' as in Go
	if r == '\n' {
		s.cpos.Line++
		s.cpos.Col = 0
	} else {
		s.cpos.Col++
	}
}
1149761
func (p *Peeker) Close() {
	for _ = range p.ch {
		// discard
	}
	// Install a synthetic EOF token in 'peeked' in case someone
	// erroneously calls Peek() or Read() after we've closed.
	p.peeked = &Token{
		Type:    EOF,
		Content: "",
	}
}