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

Unexpected behavior when reading from an already consumed Entry #157

Open
klieth opened this issue Jul 6, 2018 · 4 comments
Open

Unexpected behavior when reading from an already consumed Entry #157

klieth opened this issue Jul 6, 2018 · 4 comments

Comments

@klieth
Copy link

klieth commented Jul 6, 2018

I got caught in a really weird bug earlier that ended up being entirely my fault, but it led to me thinking a little bit about the behavior of this library. Here's effectively what happened to me (total pseudocode, but it gets the idea across):

// load an archive
let mut archive = Archive::new(/* some reader */);
// iterate through the entires
archive.entries().unwrap().for_each(|e| /* do something */);
// a while later in the code, after forgetting that I iterated them already....
archive.entries().unwrap().map(|e| /* read with e.read_to_string(&mut result) */)

All I got in return from the final line was a list of empty Strings. Which made total sense--of course you can't read from that if you've already passed the data. However, it seems that the library could have said something in that case. Would it be possible to maybe return some sort of "already consumed" error if the data isn't available? Is there something else to be done that could make this more clear?

@alexcrichton
Copy link
Owner

Seems reasonable to me! If EOF has been reached with one iterator I'd also expect it to return errors from the other iterators (or at most an empty iterator)

@klieth
Copy link
Author

klieth commented Jul 6, 2018

In my specific case, I didn't actually have two separate iterators--I'd collected one into a Vec, then used it later in a loop where I thought it was still an un-consumed Entries iterator.

@alexcrichton
Copy link
Owner

Ah true yeah, that's a known caveat for this library which should be mentioned in the documentation but is an unfortunate side effect :(

@NightRa
Copy link
Contributor

NightRa commented Oct 5, 2018

@klieth #160 / #166 should allow you to collect the entries to a Vec if really necessary.
Though you should iterate sequentially with Archive::entries to not have the entries' data stored in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants