// Returns the "logical line" from given reader
180665
func (lr *lineReader) readLine() (line string, e error) {
	if lr.exhausted {
		return "", io.EOF
	}
	nextCharIndex := 0
	char := byte(0)

	skipLF := false
	skipWhiteSpace := true
	appendedLineBegin := false
	isNewLine := true
	isCommentLine := false
	precedingBackslash := false

	for {
		if lr.offset >= lr.limit {
			lr.limit, e = io.ReadFull(lr.reader, lr.buffer)
			lr.offset = 0
			if e == io.EOF {
				lr.exhausted = true
				if isCommentLine {
					return "", io.EOF
				}
				return string(lr.lineBuffer[0:nextCharIndex]), nil
			}
			if e == io.ErrUnexpectedEOF {
				continue
			}
			if e != nil {
				lr.exhausted = true
				return "", e
			}
		}

		char = lr.buffer[lr.offset]
		lr.offset++

		if skipLF {
			skipLF = false
			if char == '\n' {
				continue
			}
		}

		if skipWhiteSpace {
			if char == ' ' || char == '\t' || char == '\f' {
				continue
			}
			if !appendedLineBegin && (char == '\r' || char == '\n') {
				continue
			}
			skipWhiteSpace = false
			appendedLineBegin = false
		}

		if isNewLine {
			isNewLine = false
			if char == '#' || char == '!' {
				isCommentLine = true
				continue
			}
		}

		if char != '\n' && char != '\r' {
			lr.lineBuffer[nextCharIndex] = char
			nextCharIndex++
			if nextCharIndex == len(lr.lineBuffer) {
				newBuffer := make([]byte, len(lr.lineBuffer)*2)
				copy(lr.lineBuffer, newBuffer)
				lr.lineBuffer = newBuffer
			}
			//flip the preceding backslash flag
			precedingBackslash = char == '\\' && !precedingBackslash
		} else {
			// reached EOL
			if isCommentLine || nextCharIndex == 0 {
				isCommentLine = false
				isNewLine = true
				skipWhiteSpace = true
				nextCharIndex = 0
				continue
			}
			if lr.offset >= lr.limit {
				lr.limit, e = io.ReadFull(lr.reader, lr.buffer)
				lr.offset = 0
				if e != nil {
					lr.exhausted = true
					return string(lr.lineBuffer[0:nextCharIndex]), nil
				}
			}
			if precedingBackslash {
				nextCharIndex--
				//skip the leading whitespace characters in following line
				skipWhiteSpace = true
				appendedLineBegin = true
				precedingBackslash = false
				if char == '\r' {
					skipLF = true
				}
			} else {
				return string(lr.lineBuffer[0:nextCharIndex]), nil
			}
		}
	}
}
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++
	}
}
277590
func Reader() io.Reader {
	var in bytes.Buffer

	for _, page := range pages {
		in.WriteString(fmt.Sprintf("\n# %s\n", page.Name))
		in.Write(MustAsset(page.File))
	}

	md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true))
	v := &renderer{}
	s := v.visit(md.Parse(in.Bytes()))
	return strings.NewReader(s)
}
1167246
func (s *translateStore) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
	return nil, pilosa.ErrReplicationNotSupported
}
956194
func (c *Connection) reader(r io.Reader) {
	buf := bufio.NewReader(r)
	frames := &reader{buf}
	conn, haveDeadliner := r.(readDeadliner)

	for {
		frame, err := frames.ReadFrame()

		if err != nil {
			c.shutdown(&Error{Code: FrameError, Reason: err.Error()})
			return
		}

		c.demux(frame)

		if haveDeadliner {
			c.deadlines <- conn
		}
	}
}
975753
func NewTailReader(ctx context.Context, r SizeReaderAt, reqLines int) (io.Reader, int, error) {
	return NewTailReaderWithDelimiter(ctx, r, reqLines, eol)
}
842594
func (r *reader) ReadHeader() (string, string, bool, error) {
	line, err := r.readLine()
	if err != nil {
		return "", "", false, err
	}
	if line := string(line); line == "\r\n" || line == "\n" {
		return "", "", true, nil
	}
	v := bytes.SplitN(line, []byte(":"), 2)
	if len(v) != 2 {
		return "", "", false, fmt.Errorf("invalid header line: %q", line)
	}
	return string(bytes.TrimSpace(v[0])), string(bytes.TrimSpace(v[1])), false, nil
}
1293077
func (f *Fetcher) Reader() io.Reader {
	return &renderer.Renderer{
		Source: f,
		Raw:    true,
	}
}
132510
func (sf *SubtitleFile) Reader() (r io.ReadCloser, err error) {
	if sf.reader != nil {
		return sf.reader, err
	}

	dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(sf.Data))
	gzReader, err := gzip.NewReader(dec)
	if err != nil {
		return nil, err
	}

	if sf.Encoding == nil {
		sf.reader = gzReader
	} else {
		sf.reader = newCloseableReader(
			sf.Encoding.NewDecoder().Reader(gzReader),
			gzReader.Close,
		)
	}

	return sf.reader, nil
}
575902
func (w *SegmentWAL) Reader() WALReader {
	return &repairingWALReader{
		wal: w,
		r:   newWALReader(w.files, w.logger),
	}
}
845544
func processIOReader(fd io.Reader, contextID string) {
	reader := bufio.NewReader(fd)
	for {
		str, err := reader.ReadString('\n')
		if err != nil {
			return
		}
		fmt.Print("[" + contextID + "]:" + str)
	}
}
47248
func (s *Scroller) readLine() ([]byte, error) {
	for {
		slice, err := s.reader.ReadSlice(delimiter)
		if err == nil {
			if s.isValid(slice) {
				return slice, nil
			}
			continue
		}
		line := append([]byte(nil), slice...)
		for err == bufio.ErrBufferFull {
			slice, err = s.reader.ReadSlice(delimiter)
			line = append(line, slice...)
		}
		switch err {
		case nil:
			if s.isValid(line) {
				return line, nil
			}
		case io.EOF:
			// Reached EOF without a delimiter,
			// so step back for next time.
			s.source.Seek(-int64(len(line)), os.SEEK_CUR)
			return nil, err
		default:
			return nil, err
		}
	}
}
1224866
func (r *LineReader) Read() ([]byte, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line     []byte
		buffer   bytes.Buffer
	)

	for isPrefix && err == nil {
		line, isPrefix, err = r.reader.ReadLine()
		buffer.Write(line)
	}
	buffer.WriteByte('\n')
	return buffer.Bytes(), err
}
774932
func (r *Reader) InitReader(b []byte) {
	r.s = b
	r.i = 0
}
1281637
func UrandomReader() (io.Reader, error) {
	urandomOnce.Do(func() {
		urandom, err := os.Open(urandomPath)
		if err != nil {
			urandomErr = fmt.Errorf("unable to open %s: %s", urandomPath, err)
			return
		}
		urandomCached = urandom
	})

	return urandomCached, urandomErr
}
723967
func (s *translateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
	// Generate remote URL.
	u, err := url.Parse(s.node.URI.String())
	if err != nil {
		return nil, err
	}
	u.Path = "/internal/translate/data"
	u.RawQuery = (url.Values{
		"offset": {strconv.FormatInt(off, 10)},
	}).Encode()

	// Connect a stream to the remote server.
	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)

	// Connect a stream to the remote server.
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, fmt.Errorf("http: cannot connect to translate store endpoint: %s", err)
	}

	// Handle error codes or return body as stream.
	switch resp.StatusCode {
	case http.StatusOK:
		return resp.Body, nil
	case http.StatusNotImplemented:
		resp.Body.Close()
		return nil, pilosa.ErrNotImplemented
	default:
		body, _ := ioutil.ReadAll(resp.Body)
		resp.Body.Close()
		return nil, fmt.Errorf("http: invalid translate store endpoint status: code=%d url=%s body=%q", resp.StatusCode, u.String(), bytes.TrimSpace(body))
	}
}
1086000
func MatchReader(pattern string, r io.RuneReader) (matched bool, err error) {
	re, err := Compile(pattern)
	if err != nil {
		return false, err
	}
	return re.MatchReader(r), nil
}