@@ -2,6 +2,8 @@ mod book;
22mod exercise;
33mod wb_editor;
44
5+ use std:: io:: Read ;
6+
57pub use book:: BookWindow as WorkbookWindow ;
68pub use wb_editor:: WorkbookEditorWindow ;
79
@@ -13,7 +15,7 @@ use eframe::epaint::ColorImage;
1315#[ cfg( not( target_arch = "wasm32" ) ) ]
1416use {
1517 rfd,
16- std:: { fs:: File , io:: BufReader , io :: Write , path:: PathBuf } ,
18+ std:: { fs:: File , io:: Write , path:: PathBuf } ,
1719 log:: { debug, error}
1820} ;
1921
@@ -194,7 +196,9 @@ pub fn save_workbook(exercises: &Vec<(String, Vec<Exercise>)>) {
194196 . set_directory ( & path)
195197 . save_file ( ) ;
196198
197- if let Some ( f) = file_path {
199+ if let Some ( mut f) = file_path {
200+ f. set_extension ( "wb" ) ;
201+
198202 let data = bincode:: serialize ( & exercises) . unwrap ( ) ;
199203 let mut file = File :: create ( & f) . unwrap ( ) ;
200204 file. write_all ( & data) . unwrap ( ) ;
@@ -248,10 +252,13 @@ pub fn load_workbook() -> Option<Vec<(String, Vec<Exercise>)>> {
248252
249253 match file_path {
250254 Some ( f) => {
251- let file = File :: open ( & f[ 0 ] ) . expect ( "File not found" ) ;
252- let reader = BufReader :: new ( file) ;
255+ let mut file = File :: open ( & f[ 0 ] ) . expect ( "File not found" ) ;
256+ let mut reader: Vec < u8 > = Vec :: new ( ) ;
257+ file. read_to_end ( & mut reader) . expect ( "Could not read file" ) ;
258+
259+
253260
254- match bincode:: deserialize_from ( reader) {
261+ match bincode:: deserialize ( & reader) {
255262 Ok ( exercises) => {
256263 debug ! ( "Workbook loaded from {:?}" , f[ 0 ] ) ;
257264 Some ( exercises)
0 commit comments