From bac6e65fbaa15eae4821c87c0094a7d106fd3b80 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 12 Mar 2019 17:36:38 -0300 Subject: [PATCH] Decoding base64 --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 3 ++- src/main.rs | 15 ++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 977b21f..c07ccf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,6 +3,19 @@ name = "RustyXML" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "base64" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "byteorder" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "deunicode" version = "0.4.3" @@ -13,6 +26,7 @@ name = "enexparser" version = "0.1.0" dependencies = [ "RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -26,5 +40,7 @@ dependencies = [ [metadata] "checksum RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9222d58bccd9e6e3b82098a2ec142ad34e5d433de986d46cec03ad3a2b5fd529" +"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum deunicode 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" "checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" diff --git a/Cargo.toml b/Cargo.toml index d778c83..fc090e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2018" [dependencies] RustyXML = "0.1.1" -slug = "0.1.4" \ No newline at end of file +slug = "0.1.4" +base64 = "0.10.1" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 033caeb..f566969 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::io::prelude::*; use std::path::Path; use std::vec::Vec; use slug::slugify; +use base64::decode; #[derive(Debug)] enum CurrentTag { @@ -49,10 +50,10 @@ impl State { ..self } } - pub fn remove_tag(self) -> Self { - Self { tag: None, - ..self } - } + // pub fn remove_tag(self) -> Self { + // Self { tag: None, + // ..self } + // } } fn create_note_storage(title: &str) -> String { @@ -76,9 +77,13 @@ fn open_tag(current_state: State, tag: &str) -> State { fn dump_resource(current_state: State) -> State { let unnamed = String::from("content"); - Path::new("data") + let content_storage = Path::new("data") .join(current_state.title.as_ref().unwrap()) .join(current_state.filename.as_ref().unwrap_or(&unnamed)); + let content = base64::decode(¤t_state.data).unwrap(); + + let mut target = File::create(content_storage).unwrap(); + target.write_all(&content).unwrap(); current_state }