@@ -5,7 +5,7 @@ pub enum Error {
55 OutputLimitExceeded ,
66 Io ( std:: io:: Error ) ,
77 BinaryParsing ( auditable_extract:: Error ) ,
8- Decompression ( miniz_oxide :: inflate :: DecompressError ) ,
8+ Decompression ( DecompressError ) ,
99 #[ cfg( feature = "serde" ) ]
1010 Json ( serde_json:: Error ) ,
1111 Utf8 ( std:: str:: Utf8Error ) ,
@@ -58,10 +58,10 @@ impl From<auditable_extract::Error> for Error {
5858 }
5959}
6060
61- impl From < miniz_oxide :: inflate :: DecompressError > for Error {
62- fn from ( e : miniz_oxide :: inflate :: DecompressError ) -> Self {
61+ impl From < DecompressError > for Error {
62+ fn from ( e : DecompressError ) -> Self {
6363 match e. status {
64- miniz_oxide :: inflate :: TINFLStatus :: HasMoreOutput => Error :: OutputLimitExceeded ,
64+ TINFLStatus :: HasMoreOutput => Error :: OutputLimitExceeded ,
6565 _ => Error :: Decompression ( e) ,
6666 }
6767 }
@@ -79,3 +79,67 @@ impl From<serde_json::Error> for Error {
7979 Self :: Json ( e)
8080 }
8181}
82+
83+ /// A copy of [miniz_oxide::inflate::DecompressError].
84+ ///
85+ /// We use our copy instead of the miniz_oxide type directly
86+ /// so that we don't have to bump semver every time `miniz_oxide` does.
87+ #[ derive( Debug ) ]
88+ pub struct DecompressError {
89+ /// Decompressor status on failure. See [TINFLStatus] for details.
90+ pub status : TINFLStatus ,
91+ /// The currently decompressed data if any.
92+ pub output : Vec < u8 > ,
93+ }
94+
95+ impl std:: fmt:: Display for DecompressError {
96+ fn fmt ( & self , f : & mut :: core:: fmt:: Formatter < ' _ > ) -> :: core:: fmt:: Result {
97+ f. write_str ( match self . status {
98+ TINFLStatus :: FailedCannotMakeProgress => "Truncated input stream" ,
99+ TINFLStatus :: BadParam => "Invalid output buffer size" ,
100+ TINFLStatus :: Adler32Mismatch => "Adler32 checksum mismatch" ,
101+ TINFLStatus :: Failed => "Invalid input data" ,
102+ TINFLStatus :: Done => unreachable ! ( ) ,
103+ TINFLStatus :: NeedsMoreInput => "Truncated input stream" ,
104+ TINFLStatus :: HasMoreOutput => "Output size exceeded the specified limit" ,
105+ } )
106+ }
107+ }
108+
109+ impl std:: error:: Error for DecompressError { }
110+
111+ impl DecompressError {
112+ pub ( crate ) fn from_miniz ( err : miniz_oxide:: inflate:: DecompressError ) -> Self {
113+ Self {
114+ status : TINFLStatus :: from_miniz ( err. status ) ,
115+ output : err. output ,
116+ }
117+ }
118+ }
119+
120+ #[ repr( i8 ) ]
121+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
122+ pub enum TINFLStatus {
123+ FailedCannotMakeProgress ,
124+ BadParam ,
125+ Adler32Mismatch ,
126+ Failed ,
127+ Done ,
128+ NeedsMoreInput ,
129+ HasMoreOutput ,
130+ }
131+
132+ impl TINFLStatus {
133+ pub ( crate ) fn from_miniz ( status : miniz_oxide:: inflate:: TINFLStatus ) -> Self {
134+ use miniz_oxide:: inflate;
135+ match status {
136+ inflate:: TINFLStatus :: FailedCannotMakeProgress => Self :: FailedCannotMakeProgress ,
137+ inflate:: TINFLStatus :: BadParam => Self :: BadParam ,
138+ inflate:: TINFLStatus :: Adler32Mismatch => Self :: Adler32Mismatch ,
139+ inflate:: TINFLStatus :: Failed => Self :: Failed ,
140+ inflate:: TINFLStatus :: Done => Self :: Done ,
141+ inflate:: TINFLStatus :: NeedsMoreInput => Self :: NeedsMoreInput ,
142+ inflate:: TINFLStatus :: HasMoreOutput => Self :: HasMoreOutput ,
143+ }
144+ }
145+ }
0 commit comments