Skip to content

bufio: reading lines is too cumbersome #4802

@bradfitz

Description

@bradfitz
Reading lines from a file is too cumbersome in Go.

People are often drawn to bufio.Reader.ReadLine because of its name, but it has a weird
signature, returning (line []byte, isPrefix bool, err error), and requires a lot of work.

ReadSlice and ReadString require a delimiter byte, which is almost always the obvious
and unsightly '\n', and also can return both a line and an EOF:
http://play.golang.org/p/LSl2Aketpg

This bug is about designing a nicer API for bufio to do the common task of looping over
lines from an io.Reader.

Things to think about:

-- functional or not, like my earlier https://golang.org/cl/6870052/ proposal
and filepath.Walk.

-- if an iterator: return either a line OR an error, but never both?

-- auto-strip line endings before giving it to the caller?

-- CRLF vs LF

-- treat the final line without line endings the same as a line with a line ending?

-- skip, fail early, or truncate lines that are longer than the bufio Reader size?

-- string or []byte? (copy or not?)

etc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions