fix: Fixed metadata not being saved
This commit is contained in:
parent
e1d4537af7
commit
81915ff4f3
@ -21,8 +21,8 @@ type UnityFile struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fileMetadata struct {
|
type fileMetadata struct {
|
||||||
startOffset int
|
StartOffset int `json:"start_offset"`
|
||||||
fileSize int
|
FileSize int `json:"file_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUnityFile(fileName string) (UnityFile, error) {
|
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
|
// Update the metadata with the new file
|
||||||
u.metadata[data.Pos] = fileMetadata{
|
u.metadata[data.Pos] = fileMetadata{
|
||||||
startOffset: u.fileSize,
|
StartOffset: u.fileSize,
|
||||||
fileSize: encodedSize,
|
FileSize: encodedSize,
|
||||||
}
|
}
|
||||||
u.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) {
|
func (u UnityFile) ReadChunk(pos world.ChunkPos) (world.ChunkData, error) {
|
||||||
m := u.metadata[pos]
|
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
|
var data world.ChunkData
|
||||||
if err := json.NewDecoder(fileReader).Decode(&data); err != nil {
|
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
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UnityFile) Close() error {
|
||||||
|
return u.fd.Close()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user