@@ -69,15 +69,15 @@ fn read_file_to_bytes_internal(path : String) -> Bytes raise IOError {
6969///|
7070fn read_file_to_string_internal (
7171 path : String ,
72- encoding ~ : String = "utf8"
72+ encoding ~ : Encoding = UTF8
7373) -> String raise IOError {
74- guard encoding == "utf8" else {
75- raise IOError (
76- "Unsupported encoding: \{ encoding } , only utf8 is supported for now" ,
77- )
74+ match encoding {
75+ UTF8 => @ffi .utf8_bytes_to_mbt_string (read_file_to_bytes_internal (path ))
76+ _ =>
77+ raise IOError (
78+ "Unsupported encoding: \{ encoding } , only \{ Encoding ::UTF8 } is supported for now" ,
79+ )
7880 }
79- let bytes = read_file_to_bytes_internal (path )
80- @ffi .utf8_bytes_to_mbt_string (bytes )
8181}
8282
8383///|
@@ -95,15 +95,19 @@ fn write_bytes_to_file_internal(
9595fn write_string_to_file_internal (
9696 path : String ,
9797 content : String ,
98- encoding ~ : String = "utf8"
98+ encoding ~ : Encoding = UTF8
9999) -> Unit raise IOError {
100- guard encoding == "utf8" else {
101- raise IOError (
102- "Unsupported encoding: \{ encoding } , only utf8 is supported for now" ,
103- )
100+ match encoding {
101+ UTF8 =>
102+ write_bytes_to_file_internal (
103+ path ,
104+ @ffi .mbt_string_to_utf8_bytes (content , false ),
105+ )
106+ _ =>
107+ raise IOError (
108+ "Unsupported encoding: \{ encoding } , only \{ Encoding ::UTF8 } is supported for now" ,
109+ )
104110 }
105- let bytes = @ffi .mbt_string_to_utf8_bytes (content , false )
106- write_bytes_to_file_internal (path , bytes )
107111}
108112
109113///|
0 commit comments