rust-mobile / ndk

Rust bindings to the Android NDK
Apache License 2.0
1.14k stars 112 forks source link

ndk/asset: Add missing `is_allocated()` and `open_file_descriptor()` #409

Closed MarijnS95 closed 1 year ago

MarijnS95 commented 1 year ago

These two functions are not exactly critical but may be useful to some developers.

is_allocated() tells us whether a backing buffer is created in RAM, or if the data is directly mmap()'ed from the APK (e.g. because no decompression was needed and alignment requirements are upheld). Note that it only returns true after the asset is "mapped" (or read in some way) via e.g get_buffer(); solely opening the asset is not enough to trigger the allocation and decompression.

open_file_descriptor() gives the user a file descriptor, which simply seems to be a dup() of that from the opened APK, together with an offset and size of the given AAsset within that APK. It also requires the asset to be stored uncompressed within the APK.