ohos-fileuri-binding
OpenHarmony File URI bindings for Rust.
This crate provides safe Rust bindings for OpenHarmony's file URI operations, allowing conversion between file paths and URIs, URI validation, and directory operations.
Features
- Convert file paths to URIs
- Convert URIs to file paths
- Get directory URI from a file URI
- Validate URI strings
- Extract file names from URIs (API 13+)
Usage
Add this to your Cargo.toml:
[]
= { = "0.1.0" }
For API 13+ features:
[]
= { = "0.1.0", = ["api-13"] }
Examples
Convert path to URI
use get_uri_from_path;
let uri = get_uri_from_path?;
println!;
Convert URI to path
use get_path_from_uri;
let path = get_path_from_uri?;
println!;
Get directory URI
use get_full_directory_uri;
let dir_uri = get_full_directory_uri?;
println!;
Validate URI
use is_valid_uri;
if is_valid_uri
Get file name (API 13+)
use get_file_name;
let filename = get_file_name?;
println!;
Error Handling
All functions return a Result<T, FileUriError> (except is_valid_uri which returns bool).
Possible errors:
PermissionError- Permission verification failedInvalidParameter- Invalid input parameterDeviceNotSupported- Device not supportedOperationNotPermitted- Operation not permittedNoSuchFileOrDirectory- No such file or directoryOutOfMemory- Out of memoryUnknown- Unknown errorNullByteError- String contains null byteConversionError- Failed to convert result from C
API Levels
This crate supports multiple OpenHarmony API levels:
- Base features: API 12+
get_file_name: API 13+
Use feature flags to enable specific API levels:
api-13throughapi-20
System Capability
SystemCapability.FileManagement.AppFileService
License
MIT OR Apache-2.0