Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
olebeck committed Jul 29, 2024
1 parent b79623e commit ac7e246
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gophertunnel
5 changes: 4 additions & 1 deletion subcommands/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (c *MergeCMD) Execute(ctx context.Context) error {
}

if _, err := os.Stat(c.outPath + "/level.dat"); err == nil {
os.RemoveAll(c.outPath)
err = os.RemoveAll(c.outPath)
if err != nil {
return err
}
}
dbOut, err := mcdb.Config{
Log: logrus.StandardLogger(),
Expand Down
Binary file modified subcommands/resourcepack-d/resourcepack-d.go
Binary file not shown.
4 changes: 2 additions & 2 deletions utils/behaviourpack/bp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func New(name string) *Pack {
Type: "data",
UUID: utils.RandSeededUUID(name + "_data_module"),
Description: "Datapack",
Version: [3]int{1, 0, 0},
Version: resource.Version{1, 0, 0},
},
},
Dependencies: []resource.Dependency{},
Expand All @@ -48,7 +48,7 @@ func New(name string) *Pack {
}
}

func (bp *Pack) AddDependency(id string, ver [3]int) {
func (bp *Pack) AddDependency(id string, ver resource.Version) {
bp.Manifest.Dependencies = append(bp.Manifest.Dependencies, resource.Dependency{
UUID: id,
Version: ver,
Expand Down
41 changes: 34 additions & 7 deletions utils/fswriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package utils

import (
"archive/zip"
"compress/flate"
"io"
"io/fs"
"os"
"path"
"sync"
)

type WriterFS interface {
Expand Down Expand Up @@ -70,22 +72,47 @@ func (o OSWriter) Create(filename string) (w io.WriteCloser, err error) {
return w, err
}

type ZipWriter struct {
Writer *zip.Writer
var deflatePool = sync.Pool{
New: func() any {
w, _ := flate.NewWriter(nil, flate.HuffmanOnly)
return w
},
}

func (z ZipWriter) Create(filename string) (w io.WriteCloser, err error) {
zw, err := z.Writer.Create(filename)
return nullCloser{zw}, err
type closePutback struct {
*flate.Writer
}

func (c *closePutback) Close() error {
if c.Writer == nil {
return nil
}
err := c.Writer.Close()
if err != nil {
return err
}
deflatePool.Put(c.Writer)
c.Writer = nil
return nil
}

func ZipCompressPool(zw *zip.Writer) {
zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
w := deflate.GetWriter(out)
return closePutback{w}, nil
w := deflatePool.Get().(*flate.Writer)
w.Reset(out)
return &closePutback{w}, nil
})
}

type ZipWriter struct {
Writer *zip.Writer
}

func (z ZipWriter) Create(filename string) (w io.WriteCloser, err error) {
zw, err := z.Writer.Create(filename)
return nullCloser{zw}, err
}

type nullCloser struct {
io.Writer
}
Expand Down
38 changes: 0 additions & 38 deletions utils/zip.go

This file was deleted.

0 comments on commit ac7e246

Please sign in to comment.