@@ -86,7 +86,7 @@ pub fn diff(base: &[u8], data: &[u8]) -> io::Result<Vec<u8>> {
86
86
unsafe {
87
87
let cctx = ZSTD_createCCtx ( ) ;
88
88
if cctx. is_null ( ) {
89
- return Err ( io:: Error :: new ( io :: ErrorKind :: Other , "cannot create CCtx" ) ) ;
89
+ return Err ( io:: Error :: other ( "cannot create CCtx" ) ) ;
90
90
}
91
91
92
92
let max_outsize = ZSTD_compressBound ( data. len ( ) ) ;
@@ -107,7 +107,7 @@ pub fn diff(base: &[u8], data: &[u8]) -> io::Result<Vec<u8>> {
107
107
108
108
if ZSTD_isError ( outsize) != 0 {
109
109
let msg = format ! ( "cannot compress ({})" , explain_error( outsize) ) ;
110
- Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) )
110
+ Err ( io:: Error :: other ( msg) )
111
111
} else {
112
112
buf. set_len ( outsize) ;
113
113
Ok ( buf)
@@ -120,18 +120,19 @@ pub fn apply(base: &[u8], delta: &[u8]) -> io::Result<Vec<u8>> {
120
120
unsafe {
121
121
let dctx = ZSTD_createDCtx ( ) ;
122
122
if dctx. is_null ( ) {
123
- return Err ( io:: Error :: new ( io :: ErrorKind :: Other , "cannot create DCtx" ) ) ;
123
+ return Err ( io:: Error :: other ( "cannot create DCtx" ) ) ;
124
124
}
125
125
ZSTD_DCtx_setMaxWindowSize ( dctx, 1 << ZSTD_WINDOWLOG_MAX ) ;
126
126
127
127
let size = ZSTD_findDecompressedSize ( delta. as_ptr ( ) as * const c_void , delta. len ( ) ) as usize ;
128
128
if size == ZSTD_CONTENTSIZE_ERROR as usize || size == ZSTD_CONTENTSIZE_UNKNOWN as usize {
129
129
ZSTD_freeDCtx ( dctx) ;
130
130
let msg = "cannot get decompress size" ;
131
- return Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) ) ;
131
+ return Err ( io:: Error :: other ( msg) ) ;
132
132
}
133
133
134
134
let mut buf: Vec < u8 > = Vec :: with_capacity ( size) ;
135
+ let _remaining = buf. spare_capacity_mut ( ) ;
135
136
buf. set_len ( size) ;
136
137
137
138
let outsize = ZSTD_decompress_usingDict (
@@ -147,13 +148,13 @@ pub fn apply(base: &[u8], delta: &[u8]) -> io::Result<Vec<u8>> {
147
148
148
149
if ZSTD_isError ( outsize) != 0 {
149
150
let msg = format ! ( "cannot decompress ({})" , explain_error( outsize) ) ;
150
- Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) )
151
+ Err ( io:: Error :: other ( msg) )
151
152
} else if outsize != size {
152
153
let msg = format ! (
153
154
"decompress size mismatch (expected {}, got {})" ,
154
155
size, outsize
155
156
) ;
156
- Err ( io:: Error :: new ( io :: ErrorKind :: Other , msg) )
157
+ Err ( io:: Error :: other ( msg) )
157
158
} else {
158
159
Ok ( buf)
159
160
}
0 commit comments