Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions zstandard_android/lib/zstandard_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ class ZstandardAndroid extends ZstandardPlatform {

@override
Future<Uint8List?> decompress(Uint8List data) async {
const int contentSizeUnknown = -1;
const int contentSizeError = -2;

final int compressedSize = data.lengthInBytes;
final Pointer<Uint8> src = malloc.allocate<Uint8>(compressedSize);
src.asTypedList(compressedSize).setAll(0, data);

final int decompressedSizeExpected =
_bindings.ZSTD_getDecompressedSize(src.cast(), compressedSize);
final int dstCapacity = decompressedSizeExpected > 0
_bindings.ZSTD_getFrameContentSize(src.cast(), compressedSize);
final int dstCapacity = (decompressedSizeExpected != contentSizeUnknown &&
decompressedSizeExpected != contentSizeError &&
decompressedSizeExpected > 0)
? decompressedSizeExpected
: compressedSize * 20;
final Pointer<Uint8> dst = malloc.allocate<Uint8>(dstCapacity);
Expand Down
9 changes: 7 additions & 2 deletions zstandard_cli/lib/src/zstandard_cli_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ class ZstandardCLI implements ZstandardInterface {
@override
Future<Uint8List?> decompress(Uint8List data) async {
if (data.isEmpty) return data;
const int contentSizeUnknown = -1;
const int contentSizeError = -2;

final int compressedSize = data.lengthInBytes;
final Pointer<Uint8> src = malloc.allocate<Uint8>(compressedSize);
src.asTypedList(compressedSize).setAll(0, data);

final int decompressedSizeExpected =
_bindings.ZSTD_getDecompressedSize(src.cast(), compressedSize);
final int dstCapacity = decompressedSizeExpected > 0
_bindings.ZSTD_getFrameContentSize(src.cast(), compressedSize);
final int dstCapacity = (decompressedSizeExpected != contentSizeUnknown &&
decompressedSizeExpected != contentSizeError &&
decompressedSizeExpected > 0)
? decompressedSizeExpected
: compressedSize * 20;
final Pointer<Uint8> dst = malloc.allocate<Uint8>(dstCapacity);
Expand Down
9 changes: 7 additions & 2 deletions zstandard_ios/lib/zstandard_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ class ZstandardIOS extends ZstandardPlatform {

@override
Future<Uint8List?> decompress(Uint8List data) async {
const int contentSizeUnknown = -1;
const int contentSizeError = -2;

final int compressedSize = data.lengthInBytes;
final Pointer<Uint8> src = malloc.allocate<Uint8>(compressedSize);
src.asTypedList(compressedSize).setAll(0, data);

final int decompressedSizeExpected =
_bindings.ZSTD_getDecompressedSize(src.cast(), compressedSize);
final int dstCapacity = decompressedSizeExpected > 0
_bindings.ZSTD_getFrameContentSize(src.cast(), compressedSize);
final int dstCapacity = (decompressedSizeExpected != contentSizeUnknown &&
decompressedSizeExpected != contentSizeError &&
decompressedSizeExpected > 0)
? decompressedSizeExpected
: compressedSize * 20;
final Pointer<Uint8> dst = malloc.allocate<Uint8>(dstCapacity);
Expand Down
9 changes: 7 additions & 2 deletions zstandard_linux/lib/zstandard_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ class ZstandardLinux extends ZstandardPlatform {

@override
Future<Uint8List?> decompress(Uint8List data) async {
const int contentSizeUnknown = -1;
const int contentSizeError = -2;

final int compressedSize = data.lengthInBytes;
final Pointer<Uint8> src = malloc.allocate<Uint8>(compressedSize);
src.asTypedList(compressedSize).setAll(0, data);

final int decompressedSizeExpected =
_bindings.ZSTD_getDecompressedSize(src.cast(), compressedSize);
final int dstCapacity = decompressedSizeExpected > 0
_bindings.ZSTD_getFrameContentSize(src.cast(), compressedSize);
final int dstCapacity = (decompressedSizeExpected != contentSizeUnknown &&
decompressedSizeExpected != contentSizeError &&
decompressedSizeExpected > 0)
? decompressedSizeExpected
: compressedSize * 20;
final Pointer<Uint8> dst = malloc.allocate<Uint8>(dstCapacity);
Expand Down
9 changes: 7 additions & 2 deletions zstandard_macos/lib/zstandard_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ class ZstandardMacOS extends ZstandardPlatform {

@override
Future<Uint8List?> decompress(Uint8List data) async {
const int contentSizeUnknown = -1;
const int contentSizeError = -2;

final int compressedSize = data.lengthInBytes;
final Pointer<Uint8> src = malloc.allocate<Uint8>(compressedSize);
src.asTypedList(compressedSize).setAll(0, data);

final int decompressedSizeExpected =
_bindings.ZSTD_getDecompressedSize(src.cast(), compressedSize);
final int dstCapacity = decompressedSizeExpected > 0
_bindings.ZSTD_getFrameContentSize(src.cast(), compressedSize);
final int dstCapacity = (decompressedSizeExpected != contentSizeUnknown &&
decompressedSizeExpected != contentSizeError &&
decompressedSizeExpected > 0)
? decompressedSizeExpected
: compressedSize * 20;
final Pointer<Uint8> dst = malloc.allocate<Uint8>(dstCapacity);
Expand Down
3 changes: 0 additions & 3 deletions zstandard_macos/macos/Classes/zstandard_macos.c

This file was deleted.

37 changes: 37 additions & 0 deletions zstandard_macos/macos/Classes/zstd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)

project(zstandard_macos_library VERSION 0.0.1 LANGUAGES C)

# Encuentra los archivos C de Zstd
file(GLOB ZSTD_SRC
"zstd/common/*.c"
"zstd/compress/*.c"
"zstd/decompress/*.c"
)

# Agrega el ejecutable para el plugin
add_library(zstandard_macos SHARED
# "Classes/plugin_code.cpp"
${ZSTD_SRC}
)

add_library(zstandard_macos SHARED
"zstandard_macos.c"
)

target_include_directories(zstandard_macos PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/zstd"
"${CMAKE_CURRENT_SOURCE_DIR}/zstd/common"
"${CMAKE_CURRENT_SOURCE_DIR}/zstd/compress"
"${CMAKE_CURRENT_SOURCE_DIR}/zstd/decompress"
)

set_target_properties(zstandard_macos PROPERTIES
PUBLIC_HEADER zstandard_macos.h
OUTPUT_NAME "zstandard_macos"
)

target_compile_definitions(zstandard_macos PUBLIC DART_SHARED_LIB)
Loading