From 81915ff4f3406ac3f2129e3a6dd14b168662f8e7 Mon Sep 17 00:00:00 2001 From: Nicholas Novak <34256932+NickyBoy89@users.noreply.github.com> Date: Mon, 11 Dec 2023 09:57:11 -0800 Subject: [PATCH] fix: Fixed metadata not being saved --- storage/unity_file.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/storage/unity_file.go b/storage/unity_file.go index a674e72..acb3146 100644 --- a/storage/unity_file.go +++ b/storage/unity_file.go @@ -21,8 +21,8 @@ type UnityFile struct { } type fileMetadata struct { - startOffset int - fileSize int + StartOffset int `json:"start_offset"` + FileSize int `json:"file_size"` } func CreateUnityFile(fileName string) (UnityFile, error) { @@ -62,8 +62,8 @@ func (u *UnityFile) WriteChunk(data world.ChunkData) error { // Update the metadata with the new file u.metadata[data.Pos] = fileMetadata{ - startOffset: u.fileSize, - fileSize: encodedSize, + StartOffset: u.fileSize, + FileSize: encodedSize, } u.fileSize += encodedSize @@ -100,9 +100,9 @@ func (u *UnityFile) ReadMetadataFile(fileName string) error { func (u UnityFile) ReadChunk(pos world.ChunkPos) (world.ChunkData, error) { m := u.metadata[pos] - u.fd.Seek(0, m.startOffset) + u.fd.Seek(0, m.StartOffset) - fileReader := io.LimitReader(u.fd, int64(m.fileSize)) + fileReader := io.LimitReader(u.fd, int64(m.FileSize)) var data world.ChunkData if err := json.NewDecoder(fileReader).Decode(&data); err != nil { @@ -111,3 +111,7 @@ func (u UnityFile) ReadChunk(pos world.ChunkPos) (world.ChunkData, error) { return data, nil } + +func (u *UnityFile) Close() error { + return u.fd.Close() +}