Auto-indexing service and GraphQL API for AT Protocol Records
at main 35 lines 1.0 kB view raw
1/// FFI wrapper around Erlang's :zip module for extracting ZIP files 2import gleam/dynamic.{type Dynamic} 3import gleam/dynamic/decode 4import gleam/string 5 6/// Extract a ZIP file to a destination directory 7/// 8/// Returns Ok(Nil) on success, Error(String) on failure 9pub fn extract_zip(zip_path: String, destination: String) -> Result(Nil, String) { 10 case do_extract_zip(zip_path, destination) { 11 Ok(_) -> Ok(Nil) 12 Error(err) -> Error(dynamic_to_string(err)) 13 } 14} 15 16/// Erlang FFI to unzip a file 17/// Uses :zip.unzip/2 with the :cwd option to specify extraction directory 18@external(erlang, "zip_helper_ffi", "unzip_file") 19fn do_extract_zip( 20 zip_path: String, 21 destination: String, 22) -> Result(Dynamic, Dynamic) 23 24/// Convert a dynamic error to a string for error reporting 25fn dynamic_to_string(value: Dynamic) -> String { 26 case decode.run(value, decode.string) { 27 Ok(str) -> str 28 Error(_) -> { 29 // Try to convert to string representation 30 case string.inspect(value) { 31 str -> str 32 } 33 } 34 } 35}