about summary refs log tree commit diff
path: root/src/gif.rs
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-10-10 14:04:56 -0500
committerGenny <gen@nyble.dev>2021-10-10 14:04:56 -0500
commit9fc5f0b1259fff2b999347f9ea326d13c222a16e (patch)
treef8194e57c86caa3b6519e30a84a0d5919c9ad5a0 /src/gif.rs
parenta4c967c5bd132d2bf9f2b151ee2ca1f4aa05f4a4 (diff)
downloadgifed-9fc5f0b1259fff2b999347f9ea326d13c222a16e.tar.gz
gifed-9fc5f0b1259fff2b999347f9ea326d13c222a16e.zip
Fix builder api, add save method
Diffstat (limited to 'src/gif.rs')
-rw-r--r--src/gif.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/gif.rs b/src/gif.rs
index 36e64dd..5b58ed1 100644
--- a/src/gif.rs
+++ b/src/gif.rs
@@ -1,4 +1,9 @@
-use crate::{block::{extension::Extension, Block, ColorTable, ScreenDescriptor, Version}, writer::GifBuilder};
+use std::{fs::File, io::Write, path::Path};
+
+use crate::{
+    block::{extension::Extension, Block, ColorTable, ScreenDescriptor, Version},
+    writer::GifBuilder,
+};
 pub struct Gif {
     pub header: Version,
     pub screen_descriptor: ScreenDescriptor,
@@ -49,6 +54,10 @@ impl Gif {
 
         out
     }
+
+    pub fn save<P: AsRef<Path>>(&self, path: P) -> std::io::Result<()> {
+        File::create(path.as_ref())?.write_all(&self.to_vec())
+    }
 }
 
 /*struct FrameIterator {
@@ -150,11 +159,9 @@ pub mod gif {
                     .palette(colortable.try_into().unwrap())
                     .indicies(&indicies),
             )
-            .unwrap()
-            .image(ImageBuilder::new(4, 4).indicies(&indicies))
-            .unwrap();
+            .image(ImageBuilder::new(4, 4).indicies(&indicies));
 
-        let bytes = actual.build().to_vec();
+        let bytes = actual.build().unwrap().to_vec();
         assert_eq!(bytes, expected_out);
     }
 
@@ -179,10 +186,9 @@ pub mod gif {
                     .disposal_method(DisposalMethod::RestoreBackground)
                     .delay(64),
             )
-            .unwrap()
             .image(ImageBuilder::new(4, 4).indicies(&indicies))
-            .unwrap()
             .build()
+            .unwrap()
             .to_vec();
 
         std::fs::File::create("ah.gif")