slovo/lib/std/fs.slo
2026-05-22 12:21:49 +02:00

231 lines
6.3 KiB
Plaintext

(module fs (export read_text read_text_result read_text_option write_text_status write_text_result exists is_file is_dir remove_file_result create_dir_result remove_file_ok create_dir_ok open_text_read_result read_open_text_result close_result read_text_via_handle_result close_ok read_text_or write_text_ok read_i32_result read_i32_option read_i32_or_zero read_i32_or read_u32_result read_u32_option read_u32_or_zero read_u32_or read_i64_result read_i64_option read_i64_or_zero read_i64_or read_u64_result read_u64_option read_u64_or_zero read_u64_or read_f64_result read_f64_option read_f64_or_zero read_f64_or read_bool_result read_bool_option read_bool_or_false read_bool_or))
(import std.result (ok_or_none_string ok_or_none_i32 ok_or_none_u32 ok_or_none_i64 ok_or_none_u64 ok_or_none_f64 ok_or_none_bool))
(fn read_text ((path string)) -> string
(std.fs.read_text path))
(fn read_text_result ((path string)) -> (result string i32)
(std.fs.read_text_result path))
(fn read_text_option ((path string)) -> (option string)
(ok_or_none_string (read_text_result path)))
(fn write_text_status ((path string) (text string)) -> i32
(std.fs.write_text path text))
(fn write_text_result ((path string) (text string)) -> (result i32 i32)
(std.fs.write_text_result path text))
(fn exists ((path string)) -> bool
(std.fs.exists path))
(fn is_file ((path string)) -> bool
(std.fs.is_file path))
(fn is_dir ((path string)) -> bool
(std.fs.is_dir path))
(fn remove_file_result ((path string)) -> (result i32 i32)
(std.fs.remove_file_result path))
(fn create_dir_result ((path string)) -> (result i32 i32)
(std.fs.create_dir_result path))
(fn remove_file_ok ((path string)) -> bool
(match (remove_file_result path)
((ok status)
true)
((err code)
false)))
(fn create_dir_ok ((path string)) -> bool
(match (create_dir_result path)
((ok status)
true)
((err code)
false)))
(fn open_text_read_result ((path string)) -> (result i32 i32)
(std.fs.open_text_read_result path))
(fn read_open_text_result ((handle i32)) -> (result string i32)
(std.fs.read_open_text_result handle))
(fn close_result ((handle i32)) -> (result i32 i32)
(std.fs.close_result handle))
(fn read_text_via_handle_result ((path string)) -> (result string i32)
(match (open_text_read_result path)
((ok handle)
(let text (result string i32) (read_open_text_result handle))
(close_result handle)
text)
((err code)
(err string i32 code))))
(fn close_ok ((handle i32)) -> bool
(match (close_result handle)
((ok status)
true)
((err code)
false)))
(fn read_text_or ((path string) (fallback string)) -> string
(match (read_text_result path)
((ok text)
text)
((err code)
fallback)))
(fn write_text_ok ((path string) (text string)) -> bool
(match (write_text_result path text)
((ok status)
true)
((err code)
false)))
(fn read_i32_result ((path string)) -> (result i32 i32)
(match (read_text_result path)
((ok text)
(std.string.parse_i32_result text))
((err code)
(err i32 i32 code))))
(fn read_i32_option ((path string)) -> (option i32)
(ok_or_none_i32 (read_i32_result path)))
(fn read_i32_or_zero ((path string)) -> i32
(match (read_i32_result path)
((ok value)
value)
((err code)
0)))
(fn read_i32_or ((path string) (fallback i32)) -> i32
(match (read_i32_result path)
((ok value)
value)
((err code)
fallback)))
(fn read_u32_result ((path string)) -> (result u32 i32)
(match (read_text_result path)
((ok text)
(std.string.parse_u32_result text))
((err code)
(err u32 i32 code))))
(fn read_u32_option ((path string)) -> (option u32)
(ok_or_none_u32 (read_u32_result path)))
(fn read_u32_or_zero ((path string)) -> u32
(match (read_u32_result path)
((ok value)
value)
((err code)
0u32)))
(fn read_u32_or ((path string) (fallback u32)) -> u32
(match (read_u32_result path)
((ok value)
value)
((err code)
fallback)))
(fn read_i64_result ((path string)) -> (result i64 i32)
(match (read_text_result path)
((ok text)
(std.string.parse_i64_result text))
((err code)
(err i64 i32 code))))
(fn read_i64_option ((path string)) -> (option i64)
(ok_or_none_i64 (read_i64_result path)))
(fn read_i64_or_zero ((path string)) -> i64
(match (read_i64_result path)
((ok value)
value)
((err code)
0i64)))
(fn read_i64_or ((path string) (fallback i64)) -> i64
(match (read_i64_result path)
((ok value)
value)
((err code)
fallback)))
(fn read_u64_result ((path string)) -> (result u64 i32)
(match (read_text_result path)
((ok text)
(std.string.parse_u64_result text))
((err code)
(err u64 i32 code))))
(fn read_u64_option ((path string)) -> (option u64)
(ok_or_none_u64 (read_u64_result path)))
(fn read_u64_or_zero ((path string)) -> u64
(match (read_u64_result path)
((ok value)
value)
((err code)
0u64)))
(fn read_u64_or ((path string) (fallback u64)) -> u64
(match (read_u64_result path)
((ok value)
value)
((err code)
fallback)))
(fn read_f64_result ((path string)) -> (result f64 i32)
(match (read_text_result path)
((ok text)
(std.string.parse_f64_result text))
((err code)
(err f64 i32 code))))
(fn read_f64_option ((path string)) -> (option f64)
(ok_or_none_f64 (read_f64_result path)))
(fn read_f64_or_zero ((path string)) -> f64
(match (read_f64_result path)
((ok value)
value)
((err code)
0.0)))
(fn read_f64_or ((path string) (fallback f64)) -> f64
(match (read_f64_result path)
((ok value)
value)
((err code)
fallback)))
(fn read_bool_result ((path string)) -> (result bool i32)
(match (read_text_result path)
((ok text)
(std.string.parse_bool_result text))
((err code)
(err bool i32 code))))
(fn read_bool_option ((path string)) -> (option bool)
(ok_or_none_bool (read_bool_result path)))
(fn read_bool_or_false ((path string)) -> bool
(match (read_bool_result path)
((ok value)
value)
((err code)
false)))
(fn read_bool_or ((path string) (fallback bool)) -> bool
(match (read_bool_result path)
((ok value)
value)
((err code)
fallback)))