aboutsummaryrefslogtreecommitdiff
path: root/core/encoding/hxa/hxa_os.odin
blob: 17ad9481902452df5f3d317c9896217b944c7281 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#+build !freestanding
#+build !js
package encoding_hxa

import "core:os"

read_from_file :: proc(filename: string, print_error := false, allocator := context.allocator, loc := #caller_location) -> (file: File, err: Read_Error) {
	context.allocator = allocator

	data, data_err := os.read_entire_file(filename, allocator, loc)
	if data_err != nil {
		err = .Unable_To_Read_File
		delete(data, allocator)
		return
	}
	file, err = read(data, filename, print_error, allocator)
	file.backing   = data
	return
}

write_to_file :: proc(filepath: string, file: File) -> (err: Write_Error) {
	required := required_write_size(file)
	buf, alloc_err := make([]byte, required)
	if alloc_err == .Out_Of_Memory {
		return .Failed_File_Write
	}
	defer delete(buf)

	write_internal(&Writer{data = buf}, file)
	if os.write_entire_file(filepath, buf) != nil {
		err =.Failed_File_Write
	}
	return
}