搜尋套件、儲存庫與 APP 分類

套件詳情v6.5.4

posix

在 OSx 和 Linux 上公開 POSIX API

AndroidiOSmacOSWindowsLinux
近 30 天下載
935萬
喜歡數
12
Pub 分數
160

安裝套件

flutter pub add posix

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

posix 套件在 macOS 和 Linux 上提供對 POSIX 系統 API 的存取,支援檔案操作、程序控制和訊號處理等底層系統作業。此套件專為需要與底層作業系統直接互動的桌面應用程式設計。透過 Dart 接口公開原生 POSIX 函數,使其適合用於進階系統程式設計任務。該套件支援 macOS、Linux、Windows、Android 及 iOS 平台,但完整 POSIX 功能主要可在 macOS 與 Linux 上取得。此套件非常適合需要對系統資源進行細微控制的開發者建構工具。

適用情境

  • 系統級檔案操作
  • 進程和線程管理
  • 桌面應用程式中的訊號處理
  • 跨平台系統實用工具
  • 底層操作系統互動

主要特色

  • 對原生 POSIX API 的存取
  • 對 macOS 與 Linux 的支援
  • 跨平台相容性
  • Dart 友好的系統呼叫包裝
  • 輕量且專注的設計

適合對象

  • 桌面應用程式開發者
  • 系統工具創建者
  • 進階 Flutter 使用者
  • 需要作業系統層級存取權限的開發者
  • 需要進程隔離的工具

使用建議

  • 非POSIX平台上的功能受限
  • 需要平台特定知識
  • 不適用於行動應用程式核心邏輯
  • 可能需要提升權限
  • 最適合桌面環境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Provides Dart access to the POSIX api for MacOS and Linux system.


import 'package:posix/posix.dart';

int uid = getuid();

Contributing

Dart types only

The api should only expose dart types. Any C types MUST be translated to dart types before being returned.

setters and getters

One of the first questsion is to whether we should use Dart's settings and getters:

e.g.


// getuid
int uid = getuid;

or

int uid = getuid();


/// setuid

uid = myuid;

or 

setuid = uid;

or

setuid(uid);

My initial thoughts is to make the api identical to the posix api which would mean that we don't use Dart setters and getters.

error returns

Do we return error no.s or do we throw.

As Dart is a modern language it uses Exception whereas posix returns error codes.

Often posix will return null and then expect you to make a separate call to 'errorno' to get the actual error no.

I'm inclined to bring the api that we expose into the modern world.

So I'm proposing that if an posix api returns an error that we throw a PosixException with a message and error code.

Adding additional functions

The process of adding additional functions is:

  1. Install ffigen
dart pub global activate ffigen
  1. Run the ffigen setup.

The paths may be different on your system. Search for clang-c/Index.h

sudo apt-get install libclang-dev
dart pub run ffigen:setup -I/usr/lib/llvm-11/include -L/usr/lib/llvm-11/lib
  1. find the required posix header file

  2. use ffigen to create the initial dart file from the header.

    • add your header file to ffigen.yaml
  3. Run ffigen

dart pub run ffigen  --config ffigen/linux.yaml 
  1. convert each method to take/return dart types.

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案