Browse code

Decoding base64

Julio Biason authored on 12/03/2019 13:36:38
Showing 3 changed files

... ...
@@ -3,6 +3,19 @@ name = "RustyXML"
3 3
 version = "0.1.1"
4 4
 source = "registry+https://github.com/rust-lang/crates.io-index"
5 5
 
6
+[[package]]
7
+name = "base64"
8
+version = "0.10.1"
9
+source = "registry+https://github.com/rust-lang/crates.io-index"
10
+dependencies = [
11
+ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
12
+]
13
+
14
+[[package]]
15
+name = "byteorder"
16
+version = "1.3.1"
17
+source = "registry+https://github.com/rust-lang/crates.io-index"
18
+
6 19
 [[package]]
7 20
 name = "deunicode"
8 21
 version = "0.4.3"
... ...
@@ -13,6 +26,7 @@ name = "enexparser"
13 26
 version = "0.1.0"
14 27
 dependencies = [
15 28
  "RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
29
+ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
16 30
  "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
17 31
 ]
18 32
 
... ...
@@ -26,5 +40,7 @@ dependencies = [
26 40
 
27 41
 [metadata]
28 42
 "checksum RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9222d58bccd9e6e3b82098a2ec142ad34e5d433de986d46cec03ad3a2b5fd529"
43
+"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
44
+"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
29 45
 "checksum deunicode 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690"
30 46
 "checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
... ...
@@ -6,4 +6,5 @@ edition = "2018"
6 6
 
7 7
 [dependencies]
8 8
 RustyXML = "0.1.1"
9
-slug = "0.1.4"
10 9
\ No newline at end of file
10
+slug = "0.1.4"
11
+base64 = "0.10.1"
11 12
\ No newline at end of file
... ...
@@ -5,6 +5,7 @@ use std::io::prelude::*;
5 5
 use std::path::Path;
6 6
 use std::vec::Vec;
7 7
 use slug::slugify;
8
+use base64::decode;
8 9
 
9 10
 #[derive(Debug)]
10 11
 enum CurrentTag {
... ...
@@ -49,10 +50,10 @@ impl State {
49 50
                ..self }
50 51
     }
51 52
 
52
-    pub fn remove_tag(self) -> Self {
53
-        Self { tag: None,
54
-               ..self }
55
-    }
53
+    // pub fn remove_tag(self) -> Self {
54
+    //     Self { tag: None,
55
+    //            ..self }
56
+    // }
56 57
 }
57 58
 
58 59
 fn create_note_storage(title: &str) -> String {
... ...
@@ -76,9 +77,13 @@ fn open_tag(current_state: State, tag: &str) -> State {
76 77
 
77 78
 fn dump_resource(current_state: State) -> State {
78 79
     let unnamed = String::from("content");
79
-    Path::new("data")
80
+    let content_storage = Path::new("data")
80 81
         .join(current_state.title.as_ref().unwrap())
81 82
         .join(current_state.filename.as_ref().unwrap_or(&unnamed));
83
+    let content = base64::decode(&current_state.data).unwrap();
84
+
85
+    let mut target = File::create(content_storage).unwrap();
86
+    target.write_all(&content).unwrap();
82 87
 
83 88
     current_state
84 89
 }