about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2022-11-27 16:35:00 -0600
committerGenny <gen@nyble.dev>2022-11-27 16:35:00 -0600
commitf6cfd151ca2214d8d09729c814f1f1e4a9d5c650 (patch)
tree1e4c1e5f02c7563c5bfbcca45670b13e1fd989f6
parentf45c0d338f9bd0eac56cbab2ff5b6d7c163e2ed0 (diff)
downloadgifed-f6cfd151ca2214d8d09729c814f1f1e4a9d5c650.tar.gz
gifed-f6cfd151ca2214d8d09729c814f1f1e4a9d5c650.zip
gifed: add non-streaming reader
-rw-r--r--gifed/src/reader/mod.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/gifed/src/reader/mod.rs b/gifed/src/reader/mod.rs
index b4d892a..d81961c 100644
--- a/gifed/src/reader/mod.rs
+++ b/gifed/src/reader/mod.rs
@@ -8,9 +8,12 @@ use std::{
 	path::Path,
 };
 
-use crate::block::{
-	extension::{Application, GraphicControl},
-	Block, CompressedImage, ImageDescriptor, Palette, ScreenDescriptor, Version,
+use crate::{
+	block::{
+		extension::{Application, GraphicControl},
+		Block, CompressedImage, ImageDescriptor, Palette, ScreenDescriptor, Version,
+	},
+	Gif,
 };
 
 pub struct Decoder<R: Read> {
@@ -54,6 +57,25 @@ impl<R: Read> Decoder<R> {
 		})
 	}
 
+	pub fn read_all(self) -> Result<Gif, DecodeError> {
+		let mut decoder = self.read()?;
+
+		let mut blocks = vec![];
+		loop {
+			match decoder.block()? {
+				Some(block) => blocks.push(block.block),
+				None => break,
+			}
+		}
+
+		Ok(Gif {
+			header: decoder.version,
+			screen_descriptor: decoder.screen_descriptor,
+			global_color_table: decoder.palette,
+			blocks,
+		})
+	}
+
 	fn read_version(&mut self) -> Result<Version, DecodeError> {
 		let mut buf = [0; 6];
 		self.reader.read_exact(&mut buf)?;