@@ -26,6 +26,7 @@ pub struct CompressStream {
26
26
state : BrotliEncoderStateStruct < StandardAlloc > ,
27
27
result : i32 ,
28
28
total_out : usize ,
29
+ last_input_offset : usize ,
29
30
}
30
31
31
32
impl Drop for CompressStream {
@@ -57,6 +58,7 @@ impl CompressStream {
57
58
state,
58
59
result : BrotliStreamResult :: Init as i32 ,
59
60
total_out : 0 ,
61
+ last_input_offset : 0 ,
60
62
} )
61
63
}
62
64
@@ -94,17 +96,21 @@ impl CompressStream {
94
96
if ret != 0 {
95
97
if available_out == 0 {
96
98
self . result = BrotliStreamResult :: NeedsMoreOutput as i32 ;
99
+ self . last_input_offset = input_offset;
97
100
Ok ( output. into_boxed_slice ( ) )
98
101
} else if available_in == 0 {
99
102
output. truncate ( output_offset) ;
100
103
self . result = BrotliStreamResult :: NeedsMoreInput as i32 ;
104
+ self . last_input_offset = input. len ( ) ;
101
105
Ok ( output. into_boxed_slice ( ) )
102
106
} else {
103
107
self . result = -1 ;
108
+ self . last_input_offset = 0 ;
104
109
Err ( JsValue :: from_str ( "Unexpected Brotli streaming compress: both available_in & available_out are not 0 after a successful processing" ) )
105
110
}
106
111
} else {
107
112
self . result = -1 ;
113
+ self . last_input_offset = 0 ;
108
114
Err ( JsValue :: from_str (
109
115
"Brotli streaming compress failed: When processing" ,
110
116
) )
@@ -136,6 +142,7 @@ impl CompressStream {
136
142
}
137
143
output. truncate ( output_offset) ;
138
144
self . result = BrotliStreamResult :: ResultSuccess as i32 ;
145
+ self . last_input_offset = 0 ;
139
146
Ok ( output. into_boxed_slice ( ) )
140
147
}
141
148
}
@@ -148,13 +155,18 @@ impl CompressStream {
148
155
pub fn result ( & self ) -> i32 {
149
156
self . result
150
157
}
158
+
159
+ pub fn last_input_offset ( & self ) -> usize {
160
+ self . last_input_offset
161
+ }
151
162
}
152
163
153
164
#[ wasm_bindgen]
154
165
pub struct DecompressStream {
155
166
state : BrotliState < StandardAlloc , StandardAlloc , StandardAlloc > ,
156
167
result : i32 ,
157
168
total_out : usize ,
169
+ last_input_offset : usize ,
158
170
}
159
171
160
172
#[ wasm_bindgen]
@@ -168,6 +180,7 @@ impl DecompressStream {
168
180
state : BrotliState :: new ( alloc, alloc, alloc) ,
169
181
result : BrotliStreamResult :: Init as i32 ,
170
182
total_out : 0 ,
183
+ last_input_offset : 0 ,
171
184
}
172
185
}
173
186
@@ -194,23 +207,27 @@ impl DecompressStream {
194
207
BrotliResult :: ResultFailure => {
195
208
// It should be a negative error code
196
209
self . result = self . state . error_code as i32 ;
210
+ self . last_input_offset = 0 ;
197
211
Err ( JsValue :: from_str ( & format ! (
198
212
"Brotli streaming decompress failed: Error code {}" ,
199
213
self . result
200
214
) ) )
201
215
}
202
216
BrotliResult :: NeedsMoreOutput => {
203
217
self . result = BrotliStreamResult :: NeedsMoreOutput as i32 ;
218
+ self . last_input_offset = input_offset;
204
219
Ok ( output. into_boxed_slice ( ) )
205
220
}
206
221
BrotliResult :: ResultSuccess => {
207
222
output. truncate ( output_offset) ;
208
223
self . result = BrotliStreamResult :: ResultSuccess as i32 ;
224
+ self . last_input_offset = input. len ( ) ;
209
225
Ok ( output. into_boxed_slice ( ) )
210
226
}
211
227
BrotliResult :: NeedsMoreInput => {
212
228
output. truncate ( output_offset) ;
213
229
self . result = BrotliStreamResult :: NeedsMoreInput as i32 ;
230
+ self . last_input_offset = input. len ( ) ;
214
231
Ok ( output. into_boxed_slice ( ) )
215
232
}
216
233
}
@@ -223,4 +240,8 @@ impl DecompressStream {
223
240
pub fn result ( & self ) -> i32 {
224
241
self . result
225
242
}
243
+
244
+ pub fn last_input_offset ( & self ) -> usize {
245
+ self . last_input_offset
246
+ }
226
247
}
0 commit comments