Skip to content

Commit

Permalink
internal/ui: use gioutil for I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
DeedleFake committed Aug 12, 2024
1 parent 5d5cdcc commit 6419272
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions internal/ui/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log/slog"

"deedles.dev/trayscale/internal/tsutil"
"github.com/diamondburned/gotk4/pkg/core/gioutil"
"github.com/diamondburned/gotk4/pkg/gio/v2"
"tailscale.com/tailcfg"
)
Expand All @@ -30,7 +31,7 @@ func (a *App) pushFile(ctx context.Context, peerID tailcfg.StableNodeID, file *g
return
}

r := greader{ctx, s}
r := gioutil.Reader(ctx, s)
err = tsutil.PushFile(ctx, peerID, info.Size(), file.Basename(), r)
if err != nil {
slog.Error("push file", "err", err)
Expand Down Expand Up @@ -60,7 +61,7 @@ func (a *App) saveFile(ctx context.Context, name string, file *gio.File) {
return
}

w := gwriter{ctx, s}
w := gioutil.Writer(ctx, s)
_, err = io.CopyN(w, r, size)
if err != nil {
slog.Error("write file", "err", err)
Expand All @@ -76,29 +77,3 @@ func (a *App) saveFile(ctx context.Context, name string, file *gio.File) {
a.poller.Poll() <- struct{}{}
slog.Info("done saving file")
}

type GOutputStream interface {
Write(context.Context, []byte) (int, error)
}

type gwriter struct {
ctx context.Context
s GOutputStream
}

func (w gwriter) Write(data []byte) (int, error) {
return w.s.Write(w.ctx, data)
}

type GInputStream interface {
Read(context.Context, []byte) (int, error)
}

type greader struct {
ctx context.Context
s GInputStream
}

func (r greader) Read(buf []byte) (int, error) {
return r.s.Read(r.ctx, buf)
}

0 comments on commit 6419272

Please sign in to comment.