mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
feat(std/wasi) implement fd_filestat_set_size (#6558)
This commit is contained in:
parent
4cde7fdc9a
commit
3c5459d849
3 changed files with 30 additions and 2 deletions
|
@ -20,7 +20,7 @@ This module provides an implementation of the WebAssembly System Interface
|
|||
- [ ] fd_fdstat_set_flags
|
||||
- [ ] fd_fdstat_set_rights
|
||||
- [x] fd_filestat_get
|
||||
- [ ] fd_filestat_set_size
|
||||
- [x] fd_filestat_set_size
|
||||
- [x] fd_filestat_set_times
|
||||
- [x] fd_pread
|
||||
- [x] fd_prestat_get
|
||||
|
|
|
@ -607,7 +607,18 @@ export default class Module {
|
|||
},
|
||||
|
||||
fd_filestat_set_size: (fd: number, size: bigint): number => {
|
||||
return ERRNO_NOSYS;
|
||||
const entry = this.fds[fd];
|
||||
if (!entry) {
|
||||
return ERRNO_BADF;
|
||||
}
|
||||
|
||||
try {
|
||||
Deno.ftruncateSync(entry.handle.rid, Number(size));
|
||||
} catch (err) {
|
||||
return errno(err);
|
||||
}
|
||||
|
||||
return ERRNO_SUCCESS;
|
||||
},
|
||||
|
||||
fd_filestat_set_times: (
|
||||
|
|
17
std/wasi/testdata/std_fs_file_set_len.rs
vendored
Normal file
17
std/wasi/testdata/std_fs_file_set_len.rs
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
// { "preopens": { "/scratch": "scratch" } }
|
||||
|
||||
fn main() {
|
||||
let file = std::fs::File::create("/scratch/file").unwrap();
|
||||
|
||||
assert!(file.set_len(0).is_ok());
|
||||
assert_eq!(file.metadata().unwrap().len(), 0);
|
||||
|
||||
assert!(file.set_len(5).is_ok());
|
||||
assert_eq!(file.metadata().unwrap().len(), 5);
|
||||
|
||||
assert!(file.set_len(25).is_ok());
|
||||
assert_eq!(file.metadata().unwrap().len(), 25);
|
||||
|
||||
assert!(file.set_len(0).is_ok());
|
||||
assert_eq!(file.metadata().unwrap().len(), 0);
|
||||
}
|
Loading…
Reference in a new issue