This repository was archived by the owner on Jun 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change 1
- pub fn decode ( bytes : Vec < u8 > ) -> Option < String > {
1
+ pub fn decode ( bytes : Vec < u8 > ) -> Result < String , String > {
2
2
use flate2:: read:: GzDecoder ;
3
3
use std:: io:: Read ;
4
4
5
5
let mut decoder = GzDecoder :: new ( & bytes[ ..] ) ;
6
6
let mut xml = String :: new ( ) ;
7
7
8
8
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 ( ) )
11
11
}
12
12
}
13
13
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 ;
17
16
use std:: io:: Read ;
18
17
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 ( ) ;
21
20
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 ( ) ) ,
25
24
}
26
25
}
You can’t perform that action at this time.
0 commit comments