mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-22 14:25:21 +00:00
Convert core:encoding/hxa
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -54,4 +54,4 @@ download_assets :: proc "contextless" () {
|
||||
@(require) import "text/regex"
|
||||
@(require) import "thread"
|
||||
@(require) import "time"
|
||||
@(require) import "unicode"
|
||||
@(require) import "unicode"
|
||||
Reference in New Issue
Block a user