summaryrefslogtreecommitdiff
path: root/plugins/warp/src/plugin/ffi/file.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-08-26 23:59:38 -0400
committerMason Reed <mason@vector35.com>2025-10-01 21:38:39 -0400
commitede39aee7e00c40a43b67ca18dd8ab80ee863d85 (patch)
tree67c5eda347ece2282e3c888f38066b496e06dec8 /plugins/warp/src/plugin/ffi/file.rs
parenta1c46813e7f279aa4cfdb9dbb91c45b559ebeacd (diff)
[WARP] Enhanced network support
Diffstat (limited to 'plugins/warp/src/plugin/ffi/file.rs')
-rw-r--r--plugins/warp/src/plugin/ffi/file.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/plugins/warp/src/plugin/ffi/file.rs b/plugins/warp/src/plugin/ffi/file.rs
new file mode 100644
index 00000000..951b5eb2
--- /dev/null
+++ b/plugins/warp/src/plugin/ffi/file.rs
@@ -0,0 +1,38 @@
+use std::ffi::c_char;
+use std::sync::Arc;
+use warp::WarpFile;
+
+pub type BNWARPFile = WarpFile<'static>;
+
+// TODO: At some point we may want to expose chunks directly. For now we will just enumerate all of them.
+// pub type BNWARPChunk = warp::chunk::Chunk<'static>;
+
+// TODO: From bytes as well.
+#[no_mangle]
+pub unsafe extern "C" fn BNWARPNewFileFromPath(path: *mut c_char) -> *mut BNWARPFile {
+ let path_cstr = unsafe { std::ffi::CStr::from_ptr(path) };
+ let Ok(path) = path_cstr.to_str() else {
+ return std::ptr::null_mut();
+ };
+ let Ok(bytes) = std::fs::read(path) else {
+ return std::ptr::null_mut();
+ };
+ let Some(file) = WarpFile::from_owned_bytes(bytes) else {
+ return std::ptr::null_mut();
+ };
+ Arc::into_raw(Arc::new(file)) as *mut BNWARPFile
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn BNWARPNewFileReference(file: *mut BNWARPFile) -> *mut BNWARPFile {
+ Arc::increment_strong_count(file);
+ file
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn BNWARPFreeFileReference(file: *mut BNWARPFile) {
+ if file.is_null() {
+ return;
+ }
+ Arc::decrement_strong_count(file);
+}