fix: Fixed decoding for empty files and added temporary directories to tests
This commit is contained in:
@@ -7,6 +7,10 @@ import (
|
||||
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||
)
|
||||
|
||||
var (
|
||||
ChunkFileDirectory = "./persistence"
|
||||
)
|
||||
|
||||
func ReadChunkFromFile(chunkFile *os.File) (world.ChunkData, error) {
|
||||
var chunkData world.ChunkData
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.nicholasnovak.io/nnovak/spatial-db/world"
|
||||
)
|
||||
@@ -17,7 +18,7 @@ type SimpleServer struct {
|
||||
// Filesystem operations
|
||||
|
||||
func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
||||
chunkFileName := pos.ToFileName()
|
||||
chunkFileName := filepath.Join(ChunkFileDirectory, pos.ToFileName())
|
||||
|
||||
var chunkData world.ChunkData
|
||||
|
||||
@@ -34,6 +35,10 @@ func (s *SimpleServer) FetchChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
||||
if err := json.NewEncoder(chunkFile).Encode(chunkData); err != nil {
|
||||
return chunkData, err
|
||||
}
|
||||
|
||||
if _, err := chunkFile.Seek(0, 0); err != nil {
|
||||
return chunkData, err
|
||||
}
|
||||
} else {
|
||||
return chunkData, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user