Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit cb7c601

Browse files
committed
changed return type from option to result to display internal error
1 parent 0b487a9 commit cb7c601

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/gzip.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
pub fn decode(bytes: Vec<u8>) -> Option<String> {
1+
pub fn decode(bytes: Vec<u8>) -> Result<String, String> {
22
use flate2::read::GzDecoder;
33
use std::io::Read;
44

55
let mut decoder = GzDecoder::new(&bytes[..]);
66
let mut xml = String::new();
77

88
match decoder.read_to_string(&mut xml) {
9-
Ok(_) => Some(xml),
10-
Err(_) => None,
9+
Ok(_) => Ok(xml),
10+
Err(error) => Err(error.to_string())
1111
}
1212
}
1313

14-
pub fn encode(content: &str) -> Option<Vec<u8>> {
15-
use flate2::read::GzEncoder;
16-
use flate2::Compression;
14+
pub fn encode(content: &str) -> Result<String, String> {
15+
use flate2::read::GzDecoder;
1716
use std::io::Read;
1817

19-
let mut encoder = GzEncoder::new(content.as_bytes(), Compression::best());
20-
let mut bytes = Vec::new();
18+
let mut decoder = GzDecoder::new(&bytes[..]);
19+
let mut xml = String::new();
2120

22-
match encoder.read_to_end(&mut bytes) {
23-
Ok(_) => Some(bytes),
24-
Err(_) => None,
21+
match decoder.read_to_string(&mut xml) {
22+
Ok(_) => Ok(xml),
23+
Err(error) => Err(error.to_string()),
2524
}
2625
}

0 commit comments

Comments
 (0)