mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Fix fs writeFile & readFile not working with invalid utf8
This commit is contained in:
parent
7261ca90ef
commit
a59b0190ab
2 changed files with 12 additions and 4 deletions
|
@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
print("Hello, world!")
|
print("Hello, world!")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed `fs.writeFile` and `fs.readFile` not working with strings / files that are invalid utf-8
|
||||||
|
|
||||||
## `0.5.5` - March 8th, 2023
|
## `0.5.5` - March 8th, 2023
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -19,8 +19,9 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||||
.build_readonly()
|
.build_readonly()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_read_file(_: &'static Lua, path: String) -> LuaResult<String> {
|
async fn fs_read_file(lua: &'static Lua, path: String) -> LuaResult<LuaString> {
|
||||||
fs::read_to_string(&path).await.map_err(LuaError::external)
|
let bytes = fs::read(&path).await.map_err(LuaError::external)?;
|
||||||
|
lua.create_string(&bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_read_dir(_: &'static Lua, path: String) -> LuaResult<Vec<String>> {
|
async fn fs_read_dir(_: &'static Lua, path: String) -> LuaResult<Vec<String>> {
|
||||||
|
@ -52,8 +53,11 @@ async fn fs_read_dir(_: &'static Lua, path: String) -> LuaResult<Vec<String>> {
|
||||||
Ok(dir_strings_no_prefix)
|
Ok(dir_strings_no_prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fs_write_file(_: &'static Lua, (path, contents): (String, String)) -> LuaResult<()> {
|
async fn fs_write_file(
|
||||||
fs::write(&path, &contents)
|
_: &'static Lua,
|
||||||
|
(path, contents): (String, LuaString<'_>),
|
||||||
|
) -> LuaResult<()> {
|
||||||
|
fs::write(&path, &contents.as_bytes())
|
||||||
.await
|
.await
|
||||||
.map_err(LuaError::external)
|
.map_err(LuaError::external)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue