🔖 Ic-merge is working now
This commit is contained in:
parent
8a3da4c5fe
commit
03fa525a00
5 changed files with 58 additions and 33 deletions
35
infinitecraft/write.go
Normal file
35
infinitecraft/write.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package infinitecraft
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (m *Merger) Write(ctx context.Context, g Game) (out string, err error) {
|
||||
base := fmt.Sprintf("%s - %s", time.Now().Local().Format("2006-01-02T15_04_05"), g.Name)
|
||||
out = base + ".ic"
|
||||
|
||||
var f *os.File
|
||||
if f, err = os.Create(out); err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
gz := gzip.NewWriter(f)
|
||||
defer gz.Close()
|
||||
gz.Name = base
|
||||
gz.ModTime = time.Unix(g.Updated/1000, g.Updated%1000)
|
||||
gz.Comment = "merge by ic-merge"
|
||||
|
||||
if g.Instances == nil {
|
||||
g.Instances = make([]any, 0)
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(gz)
|
||||
err = enc.Encode(g)
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue