we're getting there

This commit is contained in:
2026-10-11 23:01:37 +02:00
parent 83202070c7
commit 75ff309073
2 changed files with 31 additions and 3 deletions
+21 -2
View File
@@ -1,12 +1,18 @@
package pdf
import "core:os"
import "core:fmt"
PDF_MAGIC :: "%PDF-"
Error :: enum {
Ok,
File_Read_Error,
InvalidFile,
}
Document :: struct {
version: string
}
open :: proc{
@@ -14,7 +20,7 @@ open :: proc{
open_bytes,
}
open_file :: proc(path: string) -> (pdf: ^Document, err: Error) {
open_file :: proc(path: string) -> (doc: ^Document, err: Error) {
data, read_err := os.read_entire_file(path, context.allocator)
if read_err != nil {
return nil, .File_Read_Error
@@ -23,5 +29,18 @@ open_file :: proc(path: string) -> (pdf: ^Document, err: Error) {
return open_bytes(data)
}
open_bytes :: proc(data: []u8) -> (pdf: ^Document, err: Error) {
open_bytes :: proc(data: []u8) -> (doc: ^Document, err: Error) {
doc = new(Document)
if string(data[:5]) != PDF_MAGIC {
return nil, .InvalidFile
}
doc.version = string(data[5:5+3])
return doc, nil
}
destroy_document :: proc(pdf: ^Document) {
free(pdf)
}