Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poss. error in docs for tar.Reader #1677

Closed
mark-summerfield opened this issue Apr 8, 2011 · 5 comments
Closed

poss. error in docs for tar.Reader #1677

mark-summerfield opened this issue Apr 8, 2011 · 5 comments

Comments

@mark-summerfield
Copy link

The tar.Reader docs give this example:

tr := tar.NewReader(r)
for {
    hdr, err := tr.Next()
    if err != nil {
        // handle error
    }
    if hdr == nil {
        // end of tar archive
        break
    }
    io.Copy(data, tr)
}

But when I tried it it failed because I hit EOF. So either the tar package isn't working
correctly (i.e., not as documented), or the example needs to be changed to something
like this (which I've tried and works):

tr := tar.NewReader(r)
for {
    hdr, err := tr.Next()
    if err != nil {
                if err == os.EOF {
                    break
                }
        // handle error
    }
    if hdr == nil {
        // end of tar archive
        break
    }
    io.Copy(data, tr)
}
@dchest
Copy link
Contributor

dchest commented Apr 8, 2011

Comment 1:

"// handle error" means exactly what you did.

@dchest
Copy link
Contributor

dchest commented Apr 8, 2011

Comment 2:

Although your example looks more correct giving the context.

@robpike
Copy link
Contributor

robpike commented Apr 12, 2011

Comment 3:

Owner changed to @dsymonds.

Status changed to Accepted.

@dsymonds
Copy link
Contributor

Comment 4:

Status changed to Started.

@dsymonds
Copy link
Contributor

Comment 5:

This issue was closed by revision 1de71a0.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants