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

Refactor Pxo::Load to use std::io::Read + std::io::Seek #3

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ let (packed, image) = pxo::PackedSprite::pack_sprites(&[sprite_a, sprite_b], 204
```
*/

use std::{
fs::File,
io::{BufRead, BufReader},
};

use decompress::decompress;
use image::RgbaImage;
use images::load_images;
Expand All @@ -67,8 +62,10 @@ pub use pack::PackedFrame;
#[cfg(feature = "pack")]
pub use pack::PackedSprite;

impl ReadExt for BufReader<File> {}
impl ReadExt for BufReader<&[u8]> {}
impl<T> ReadExt for T
where
T: std::io::Read,
{}

#[cfg(feature = "sprite")]
pub use sprite::Sprite;
Expand All @@ -93,9 +90,9 @@ pub struct Pxo {

impl Pxo {
/// Loads a [Pxo] from a file
pub fn load(file: File) -> Result<Pxo, PxoError> {
let mut reader = BufReader::new(file);
pub fn load(mut reader: impl std::io::Read + std::io::Seek) -> Result<Pxo, PxoError> {
let decompressed = decompress(&mut reader)?;
use std::io::{BufReader, BufRead};
let mut reader = BufReader::new(decompressed.as_slice());

let mut json = String::new();
Expand Down