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

Use a BufReader as underlying reader. #286

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Implement `ResourceReader` for appropiate functions. (#272) **Read the README's FAQ for more information about this change.**
- Support for custom type properties. (#283)

### Changed
- Underlying reader for maps now uses a BufReader, which should give a large performance boost. (#286)

## Fixed
- `ObjectShape::Text::kerning`'s default value, which should have been set to `true` instead of `false`. (#278)

Expand Down
6 changes: 4 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::BufReader;
use std::{fs::File, io::Read, path::Path};

/// A trait defining types that can load data from a [`ResourcePath`](crate::ResourcePath).
Expand Down Expand Up @@ -48,11 +49,12 @@ impl FilesystemResourceReader {
}

impl ResourceReader for FilesystemResourceReader {
type Resource = File;
type Resource = BufReader<File>;
type Error = std::io::Error;

fn read_from(&mut self, path: &Path) -> std::result::Result<Self::Resource, Self::Error> {
File::open(path)
let file = File::open(path)?;
Ok(BufReader::new(file))
}
}

Expand Down
Loading