| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/filter.h" | 6 #include "bin/filter.h" |
| 7 #include "bin/io_buffer.h" | 7 #include "bin/io_buffer.h" |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 | 10 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void FUNCTION_NAME(Filter_Processed)(Dart_NativeArguments args) { | 128 void FUNCTION_NAME(Filter_Processed)(Dart_NativeArguments args) { |
| 129 Dart_EnterScope(); | 129 Dart_EnterScope(); |
| 130 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 130 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| 131 Filter* filter = GetFilter(filter_obj); | 131 Filter* filter = GetFilter(filter_obj); |
| 132 Dart_Handle flush_obj = Dart_GetNativeArgument(args, 1); | 132 Dart_Handle flush_obj = Dart_GetNativeArgument(args, 1); |
| 133 bool flush; | 133 bool flush; |
| 134 if (Dart_IsError(Dart_BooleanValue(flush_obj, &flush))) { | 134 if (Dart_IsError(Dart_BooleanValue(flush_obj, &flush))) { |
| 135 Dart_ThrowException(DartUtils::NewInternalError( | 135 Dart_ThrowException(DartUtils::NewInternalError( |
| 136 "Failed to get 'flush' parameter")); | 136 "Failed to get 'flush' parameter")); |
| 137 } | 137 } |
| 138 Dart_Handle end_obj = Dart_GetNativeArgument(args, 2); |
| 139 bool end; |
| 140 if (Dart_IsError(Dart_BooleanValue(end_obj, &end))) { |
| 141 Dart_ThrowException(DartUtils::NewInternalError( |
| 142 "Failed to get 'end' parameter")); |
| 143 } |
| 138 intptr_t read = filter->Processed(filter->processed_buffer(), | 144 intptr_t read = filter->Processed(filter->processed_buffer(), |
| 139 filter->processed_buffer_size(), | 145 filter->processed_buffer_size(), |
| 140 flush); | 146 flush, |
| 147 end); |
| 141 if (read < 0) { | 148 if (read < 0) { |
| 142 // Error, end filter. | 149 // Error, end filter. |
| 143 EndFilter(filter_obj, filter); | 150 EndFilter(filter_obj, filter); |
| 144 Dart_ThrowException(DartUtils::NewInternalError( | 151 Dart_ThrowException(DartUtils::NewInternalError( |
| 145 "Filter error, bad data")); | 152 "Filter error, bad data")); |
| 146 } else if (read == 0) { | 153 } else if (read == 0) { |
| 147 Dart_SetReturnValue(args, Dart_Null()); | 154 Dart_SetReturnValue(args, Dart_Null()); |
| 148 } else { | 155 } else { |
| 149 uint8_t* io_buffer; | 156 uint8_t* io_buffer; |
| 150 Dart_Handle result = IOBuffer::Allocate(read, &io_buffer); | 157 Dart_Handle result = IOBuffer::Allocate(read, &io_buffer); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 216 |
| 210 bool ZLibDeflateFilter::Process(uint8_t* data, intptr_t length) { | 217 bool ZLibDeflateFilter::Process(uint8_t* data, intptr_t length) { |
| 211 if (current_buffer_ != NULL) return false; | 218 if (current_buffer_ != NULL) return false; |
| 212 stream_.avail_in = length; | 219 stream_.avail_in = length; |
| 213 stream_.next_in = current_buffer_ = data; | 220 stream_.next_in = current_buffer_ = data; |
| 214 return true; | 221 return true; |
| 215 } | 222 } |
| 216 | 223 |
| 217 intptr_t ZLibDeflateFilter::Processed(uint8_t* buffer, | 224 intptr_t ZLibDeflateFilter::Processed(uint8_t* buffer, |
| 218 intptr_t length, | 225 intptr_t length, |
| 219 bool flush) { | 226 bool flush, |
| 227 bool end) { |
| 220 stream_.avail_out = length; | 228 stream_.avail_out = length; |
| 221 stream_.next_out = buffer; | 229 stream_.next_out = buffer; |
| 222 switch (deflate(&stream_, flush ? Z_SYNC_FLUSH : Z_NO_FLUSH)) { | 230 switch (deflate(&stream_, |
| 231 end ? Z_FINISH : flush ? Z_SYNC_FLUSH : Z_NO_FLUSH)) { |
| 232 case Z_STREAM_END: |
| 233 case Z_BUF_ERROR: |
| 223 case Z_OK: { | 234 case Z_OK: { |
| 224 intptr_t processed = length - stream_.avail_out; | 235 intptr_t processed = length - stream_.avail_out; |
| 225 if (processed == 0) { | 236 if (processed == 0) { |
| 226 delete[] current_buffer_; | 237 delete[] current_buffer_; |
| 227 current_buffer_ = NULL; | 238 current_buffer_ = NULL; |
| 228 return 0; | 239 return 0; |
| 229 } else { | 240 } else { |
| 230 // We processed data, should be called again. | 241 // We processed data, should be called again. |
| 231 return processed; | 242 return processed; |
| 232 } | 243 } |
| 233 } | 244 } |
| 234 | 245 |
| 235 case Z_STREAM_END: | |
| 236 case Z_BUF_ERROR: | |
| 237 // We processed all available input data. | |
| 238 delete[] current_buffer_; | |
| 239 current_buffer_ = NULL; | |
| 240 return 0; | |
| 241 | |
| 242 default: | 246 default: |
| 243 case Z_STREAM_ERROR: | 247 case Z_STREAM_ERROR: |
| 244 // An error occoured. | 248 // An error occoured. |
| 245 delete[] current_buffer_; | 249 delete[] current_buffer_; |
| 246 current_buffer_ = NULL; | 250 current_buffer_ = NULL; |
| 247 return -1; | 251 return -1; |
| 248 } | 252 } |
| 249 } | 253 } |
| 250 | 254 |
| 251 | 255 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 272 bool ZLibInflateFilter::Process(uint8_t* data, intptr_t length) { | 276 bool ZLibInflateFilter::Process(uint8_t* data, intptr_t length) { |
| 273 if (current_buffer_ != NULL) return false; | 277 if (current_buffer_ != NULL) return false; |
| 274 stream_.avail_in = length; | 278 stream_.avail_in = length; |
| 275 stream_.next_in = current_buffer_ = data; | 279 stream_.next_in = current_buffer_ = data; |
| 276 return true; | 280 return true; |
| 277 } | 281 } |
| 278 | 282 |
| 279 | 283 |
| 280 intptr_t ZLibInflateFilter::Processed(uint8_t* buffer, | 284 intptr_t ZLibInflateFilter::Processed(uint8_t* buffer, |
| 281 intptr_t length, | 285 intptr_t length, |
| 282 bool flush) { | 286 bool flush, |
| 287 bool end) { |
| 283 stream_.avail_out = length; | 288 stream_.avail_out = length; |
| 284 stream_.next_out = buffer; | 289 stream_.next_out = buffer; |
| 285 switch (inflate(&stream_, flush ? Z_SYNC_FLUSH : Z_NO_FLUSH)) { | 290 switch (inflate(&stream_, |
| 291 end ? Z_FINISH : flush ? Z_SYNC_FLUSH : Z_NO_FLUSH)) { |
| 286 case Z_STREAM_END: | 292 case Z_STREAM_END: |
| 287 case Z_BUF_ERROR: | 293 case Z_BUF_ERROR: |
| 288 case Z_OK: { | 294 case Z_OK: { |
| 289 intptr_t processed = length - stream_.avail_out; | 295 intptr_t processed = length - stream_.avail_out; |
| 290 if (processed == 0) { | 296 if (processed == 0) { |
| 291 delete[] current_buffer_; | 297 delete[] current_buffer_; |
| 292 current_buffer_ = NULL; | 298 current_buffer_ = NULL; |
| 293 return 0; | 299 return 0; |
| 294 } else { | 300 } else { |
| 295 // We processed data, should be called again. | 301 // We processed data, should be called again. |
| 296 return processed; | 302 return processed; |
| 297 } | 303 } |
| 298 } | 304 } |
| 299 | 305 |
| 300 default: | 306 default: |
| 301 case Z_MEM_ERROR: | 307 case Z_MEM_ERROR: |
| 302 case Z_NEED_DICT: | 308 case Z_NEED_DICT: |
| 303 case Z_DATA_ERROR: | 309 case Z_DATA_ERROR: |
| 304 case Z_STREAM_ERROR: | 310 case Z_STREAM_ERROR: |
| 305 // An error occoured. | 311 // An error occoured. |
| 306 delete[] current_buffer_; | 312 delete[] current_buffer_; |
| 307 current_buffer_ = NULL; | 313 current_buffer_ = NULL; |
| 308 return -1; | 314 return -1; |
| 309 } | 315 } |
| 310 } | 316 } |
| 311 | 317 |
| 312 } // namespace bin | 318 } // namespace bin |
| 313 } // namespace dart | 319 } // namespace dart |
| OLD | NEW |