@@ -5,7 +5,7 @@ mod zlib {
5
5
use crate :: common:: lock:: PyMutex ;
6
6
use crate :: vm:: {
7
7
builtins:: { PyBaseExceptionRef , PyBytes , PyBytesRef , PyIntRef , PyTypeRef } ,
8
- function:: { ArgBytesLike , OptionalArg } ,
8
+ function:: { ArgBytesLike , OptionalArg , OptionalOption } ,
9
9
IntoPyRef , PyResult , PyValue , VirtualMachine ,
10
10
} ;
11
11
use adler32:: RollingAdler32 as Adler32 ;
@@ -90,14 +90,21 @@ mod zlib {
90
90
}
91
91
}
92
92
93
+ #[ derive( FromArgs ) ]
94
+ struct PyFuncCompressArgs {
95
+ #[ pyarg( positional) ]
96
+ data : ArgBytesLike ,
97
+ #[ pyarg( any, optional) ]
98
+ level : OptionalOption < i32 > ,
99
+ }
100
+
93
101
/// Returns a bytes object containing compressed data.
94
102
#[ pyfunction]
95
- fn compress (
96
- data : ArgBytesLike ,
97
- level : OptionalArg < i32 > ,
98
- vm : & VirtualMachine ,
99
- ) -> PyResult < PyBytesRef > {
100
- let compression = compression_from_int ( level. into_option ( ) )
103
+ fn compress ( args : PyFuncCompressArgs , vm : & VirtualMachine ) -> PyResult < PyBytesRef > {
104
+ let data = args. data ;
105
+ let level = args. level ;
106
+
107
+ let compression = compression_from_int ( level. flatten ( ) )
101
108
. ok_or_else ( || new_zlib_error ( "Bad compression level" , vm) ) ?;
102
109
103
110
let mut encoder = ZlibEncoder :: new ( Vec :: new ( ) , compression) ;
@@ -223,14 +230,22 @@ mod zlib {
223
230
}
224
231
}
225
232
226
- /// Returns a bytes object containing the uncompressed data.
227
- # [ pyfunction ]
228
- fn decompress (
233
+ # [ derive ( FromArgs ) ]
234
+ struct PyFuncDecompressArgs {
235
+ # [ pyarg ( positional ) ]
229
236
data : ArgBytesLike ,
237
+ #[ pyarg( any, optional) ]
230
238
wbits : OptionalArg < i8 > ,
239
+ #[ pyarg( any, optional) ]
231
240
bufsize : OptionalArg < usize > ,
232
- vm : & VirtualMachine ,
233
- ) -> PyResult < Vec < u8 > > {
241
+ }
242
+
243
+ /// Returns a bytes object containing the uncompressed data.
244
+ #[ pyfunction]
245
+ fn decompress ( arg : PyFuncDecompressArgs , vm : & VirtualMachine ) -> PyResult < Vec < u8 > > {
246
+ let data = arg. data ;
247
+ let wbits = arg. wbits ;
248
+ let bufsize = arg. bufsize ;
234
249
data. with_ref ( |data| {
235
250
let bufsize = bufsize. unwrap_or ( DEF_BUF_SIZE ) ;
236
251
0 commit comments