mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-13 11:53:41 +00:00
feat: direct call download api by cgo dart
This commit is contained in:
1 parent
467ada5500
commit
91dfd78b77
71 files changed
+6936
-1883
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,36 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
import '../libgopeed_interface.dart';
|
||||
import 'libgopeed_bind.dart';
|
||||
|
||||
class LibgopeedFFi implements LibgopeedAbi {
|
||||
late LibgopeedBind _libgopeed;
|
||||
|
||||
LibgopeedFFi(LibgopeedBind libgopeed) {
|
||||
_libgopeed = libgopeed;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> create(String cfg) {
|
||||
final cfgPtr = cfg.toNativeUtf8();
|
||||
try {
|
||||
final result = _libgopeed.Create(cfgPtr.cast());
|
||||
return Future.value(result.cast<Utf8>().toDartString());
|
||||
} finally {
|
||||
calloc.free(cfgPtr);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> invoke(int instance, String params) {
|
||||
final paramsPtr = params.toNativeUtf8();
|
||||
try {
|
||||
final result = _libgopeed.Invoke(instance, paramsPtr.cast());
|
||||
return Future.value(result.cast<Utf8>().toDartString());
|
||||
} finally {
|
||||
calloc.free(paramsPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user