Convert core:encoding/hxa

This commit is contained in:
Jeroen van Rijn
2025-10-28 00:40:07 +01:00
parent 203a282271
commit a4a80b0c32
4 changed files with 10 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
package encoding_hxa
import "core:fmt"
import "core:os"
import os "core:os/os2"
import "core:mem"
Read_Error :: enum {
@@ -14,13 +14,13 @@ Read_Error :: enum {
read_from_file :: proc(filename: string, print_error := false, allocator := context.allocator, loc := #caller_location) -> (file: File, err: Read_Error) {
context.allocator = allocator
data, ok := os.read_entire_file(filename, allocator, loc)
if !ok {
data, data_err := os.read_entire_file(filename, allocator)
if data_err != nil {
err = .Unable_To_Read_File
delete(data, allocator, loc)
return
}
file, err = read(data, filename, print_error, allocator, loc)
file, err = read(data, filename, print_error, allocator)
file.backing = data
return
}

View File

@@ -1,7 +1,7 @@
package encoding_hxa
import "core:os"
import "core:mem"
import os "core:os/os2"
import "core:mem"
Write_Error :: enum {
None,
@@ -18,7 +18,7 @@ write_to_file :: proc(filepath: string, file: File) -> (err: Write_Error) {
defer delete(buf)
write_internal(&Writer{data = buf}, file)
if !os.write_entire_file(filepath, buf) {
if os.write_entire_file(filepath, buf) != nil {
err =.Failed_File_Write
}
return

View File

@@ -9,17 +9,15 @@ import "core:testing"
TEAPOT_PATH :: ODIN_ROOT + "tests/core/assets/HXA/teapot.hxa"
import "core:os"
import os "core:os/os2"
@test
test_read :: proc(t: ^testing.T) {
data, _ := os.read_entire_file(TEAPOT_PATH)
// file, err := hxa.read_from_file(TEAPOT_PATH)
data, _ := os.read_entire_file(TEAPOT_PATH, context.allocator)
file, err := hxa.read(data)
file.backing = data
file.allocator = context.allocator
hxa.file_destroy(file)
// fmt.printfln("%#v", file)
e :: hxa.Read_Error.None
testing.expectf(t, err == e, "read_from_file(%v) -> %v != %v", TEAPOT_PATH, err, e)

View File

@@ -52,4 +52,4 @@ download_assets :: proc "contextless" () {
@(require) import "text/regex"
@(require) import "thread"
@(require) import "time"
@(require) import "unicode"
@(require) import "unicode"