Skip to content

Conversation

@nocthir
Copy link
Contributor

@nocthir nocthir commented Sep 23, 2025

Move Archive to store a File instead of a BufReader<File> and create BufReader instances on demand inside methods. This relaxes method receivers from &mut self to &self where possible (e.g., read_file, list), which enables sharing an Archive across threads and reading multiple files concurrently from the same archive. Updated benches, examples, and tests accordingly.

No breaking changes. Method receivers changed from &mut self to &self are source compatible; existing code using &mut self can still call these methods.

BufReader objects are created on the fly when needed. With this, archive
objects can be non mutable in some cases, especially when reading files,
and that allows multiple references to exist while reading multiple files
concurrently.
@nocthir
Copy link
Contributor Author

nocthir commented Sep 24, 2025

Multiple BufReader reading from the same underlying file handle (including handles created via File::try_clone) is not safe logically: they share a single file cursor, so reads will interleave and corrupt each other’s view. The BufReader docs explicitly warn that “creating multiple instances of a BufReader on the same stream can cause data loss” because each keeps its own buffer while the shared cursor moves underneath.

@nocthir nocthir closed this Sep 24, 2025
@nocthir nocthir deleted the non-mut-archive branch September 26, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant