mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
os: add os.write_bytes/2 as a complement to os.read_bytes/1, add test
This commit is contained in:
parent
81e84a6a01
commit
2cfeb6d07b
@ -62,6 +62,12 @@ pub fn read_bytes(path string) ![]u8 {
|
||||
return res
|
||||
}
|
||||
|
||||
// write_bytes writes all the `bytes` to `path`.
|
||||
@[manualfree]
|
||||
pub fn write_bytes(path string, bytes []u8) ! {
|
||||
write_file_array(path, bytes)!
|
||||
}
|
||||
|
||||
fn find_cfile_size(fp &C.FILE) !int {
|
||||
// NB: Musl's fseek returns -1 for virtual files, while Glibc's fseek returns 0
|
||||
cseek := C.fseek(fp, 0, C.SEEK_END)
|
||||
|
@ -784,6 +784,15 @@ fn test_write_file_array_bytes() {
|
||||
// eprintln(rarr.str())
|
||||
}
|
||||
|
||||
fn test_write_bytes() {
|
||||
fpath := './wbytes.bin'
|
||||
for arr in [[u8(65), 66, 67, 68, 69, 70], [u8(3), 2, 1], []u8{}] {
|
||||
os.write_bytes(fpath, arr)!
|
||||
rarr := os.read_bytes(fpath)!
|
||||
assert arr == rarr
|
||||
}
|
||||
}
|
||||
|
||||
fn test_write_file_array_structs() {
|
||||
fpath := './astructs.bin'
|
||||
mut arr := []IntPoint{len: maxn}
|
||||
|
Loading…
x
Reference in New Issue
Block a user