36 uint8_t** dictionary) {
37 ASSERT(dictionary !=
nullptr);
38 uint8_t* src =
nullptr;
47 uint8_t*
result =
new uint8_t[size];
53 reinterpret_cast<void**
>(&src), &size);
55 memmove(
result, src, size);
78 uint8_t* dictionary =
nullptr;
79 intptr_t dictionary_length = 0;
85 ASSERT(dictionary !=
nullptr);
86 dictionary_length = 0;
95 static_cast<int32_t
>(window_bits), dictionary, dictionary_length, raw);
96 if (filter ==
nullptr) {
101 if (!filter->
Init()) {
106 err = Filter::SetFilterAndCreateFinalizer(
107 filter_obj, filter,
sizeof(*filter) + dictionary_length);
132 uint8_t* dictionary =
nullptr;
133 intptr_t dictionary_length = 0;
139 ASSERT(dictionary !=
nullptr);
140 dictionary_length = 0;
149 gzip,
static_cast<int32_t
>(level),
static_cast<int32_t
>(window_bits),
150 static_cast<int32_t
>(mem_level),
static_cast<int32_t
>(strategy),
151 dictionary, dictionary_length, raw);
152 if (filter ==
nullptr) {
157 if (!filter->
Init()) {
163 filter_obj, filter,
sizeof(*filter) + dictionary_length);
175 intptr_t chunk_length =
end -
start;
178 uint8_t*
buffer =
nullptr;
193 "Invalid argument passed to Filter_Process"));
195 uint8_t* zlib_buffer =
new uint8_t[chunk_length];
196 if (zlib_buffer ==
nullptr) {
201 memmove(zlib_buffer,
buffer +
start, chunk_length);
209 buffer =
new uint8_t[chunk_length];
223 "Call to Process while still processing data"));
245 }
else if (
read == 0) {
260 Filter* filter =
reinterpret_cast<Filter*
>(filter_pointer);
269 reinterpret_cast<intptr_t
>(filter_pointer));
279 Filter** filter_pointer) {
282 reinterpret_cast<intptr_t*
>(filter_pointer));
286 delete[] dictionary_;
287 delete[] current_buffer_;
289 deflateEnd(&stream_);
294 int window_bits = window_bits_;
295 if ((raw_ || gzip_) && (window_bits == 8)) {
306 window_bits = -window_bits;
310 stream_.next_in = Z_NULL;
311 stream_.zalloc = Z_NULL;
312 stream_.zfree = Z_NULL;
313 stream_.opaque = Z_NULL;
314 int result = deflateInit2(&stream_, level_, Z_DEFLATED, window_bits,
315 mem_level_, strategy_);
319 if ((dictionary_ !=
nullptr) && !gzip_ && !raw_) {
320 result = deflateSetDictionary(&stream_, dictionary_, dictionary_length_);
321 delete[] dictionary_;
322 dictionary_ =
nullptr;
332 if (current_buffer_ !=
nullptr) {
335 stream_.avail_in =
length;
336 stream_.next_in = current_buffer_ =
data;
344 stream_.avail_out =
length;
345 stream_.next_out =
buffer;
347 switch (deflate(&stream_,
end ? Z_FINISH
348 : flush ? Z_SYNC_FLUSH
353 intptr_t processed =
length - stream_.avail_out;
354 if (processed == 0) {
365 delete[] current_buffer_;
366 current_buffer_ =
nullptr;
368 return error ? -1 : 0;
372 delete[] dictionary_;
373 delete[] current_buffer_;
375 inflateEnd(&stream_);
383 stream_.next_in = Z_NULL;
384 stream_.avail_in = 0;
385 stream_.zalloc = Z_NULL;
386 stream_.zfree = Z_NULL;
387 stream_.opaque = Z_NULL;
388 int result = inflateInit2(&stream_, window_bits);
397 if (current_buffer_ !=
nullptr) {
400 stream_.avail_in =
length;
401 stream_.next_in = current_buffer_ =
data;
409 stream_.avail_out =
length;
410 stream_.next_out =
buffer;
413 switch (v = inflate(&stream_,
end ? Z_FINISH
414 : flush ? Z_SYNC_FLUSH
419 intptr_t processed =
length - stream_.avail_out;
420 if (processed == 0) {
427 if (dictionary_ ==
nullptr) {
431 inflateSetDictionary(&stream_, dictionary_, dictionary_length_);
432 delete[] dictionary_;
433 dictionary_ =
nullptr;
449 delete[] current_buffer_;
450 current_buffer_ =
nullptr;
452 return error ? -1 : 0;
static bool read(SkStream *stream, void *buffer, size_t amount)
#define FUNCTION_NAME(name)
static Dart_Handle NewDartFormatException(const char *message)
static int64_t GetIntegerValue(Dart_Handle value_obj)
static int64_t GetInt64ValueCheckRange(Dart_Handle value_obj, int64_t lower, int64_t upper)
static Dart_Handle NewDartOSError()
static bool GetBooleanValue(Dart_Handle bool_obj)
static Dart_Handle NewInternalError(const char *message)
static intptr_t GetIntptrValue(Dart_Handle value_obj)
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)=0
virtual bool Process(uint8_t *data, intptr_t length)=0
intptr_t processed_buffer_size() const
uint8_t * processed_buffer()
void set_initialized(bool value)
static Dart_Handle Allocate(intptr_t size, uint8_t **buffer)
virtual bool Process(uint8_t *data, intptr_t length)
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)
virtual ~ZLibDeflateFilter()
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)
virtual ~ZLibInflateFilter()
virtual bool Process(uint8_t *data, intptr_t length)
struct _Dart_Handle * Dart_Handle
struct _Dart_NativeArguments * Dart_NativeArguments
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
void FUNCTION_NAME() Filter_Processed(Dart_NativeArguments args)
void FUNCTION_NAME() Filter_Process(Dart_NativeArguments args)
static void DeleteFilter(void *isolate_data, void *filter_pointer)
const int kZLibFlagAcceptAnyHeader
const int kZLibFlagUseGZipHeader
static Dart_Handle CopyDictionary(Dart_Handle dictionary_obj, uint8_t **dictionary)
static constexpr int kFilterPointerNativeField
void FUNCTION_NAME() Filter_CreateZLibDeflate(Dart_NativeArguments args)
void FUNCTION_NAME() Filter_CreateZLibInflate(Dart_NativeArguments args)
static Dart_Handle GetFilter(Dart_Handle filter_obj, Filter **filter)
DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, int index, intptr_t *value)
constexpr int32_t kMinInt32
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT Dart_FinalizableHandle Dart_NewFinalizableHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, Dart_TypedData_Type *type, void **data, intptr_t *len)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, int index, intptr_t value)
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, intptr_t offset, uint8_t *native_array, intptr_t length)
DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object)
constexpr int32_t kMaxInt32
DART_EXPORT Dart_Handle Dart_NewApiError(const char *error)
DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t *len)
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_Null()
static int8_t data[kExtLength]