omarchy-send/internal/client/progress.go
28allday 2dd81700c0 Initial commit: Omarchy-Send v0.1.0
LocalSend-compatible file-transfer TUI for headless Arch/Omarchy servers.

- Pure-stdlib implementation of the LocalSend v2 protocol (discovery,
  HTTPS with matching cert fingerprint, send/receive, PIN).
- Bubble Tea TUI: Devices, Transfers, Manage (received-file housekeeping)
  and Settings, theme-aware on Omarchy.
- Dual-mode install.sh: curl-pipe download or build-from-clone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 19:26:08 +01:00

28 lines
548 B
Go

package client
import (
"io"
"time"
)
// progressReader wraps a file reader, emitting throttled byte-count callbacks as
// the body is streamed to the peer.
type progressReader struct {
r io.Reader
total int64
read int64
emit func(sent int64)
lastEmit time.Time
}
func (p *progressReader) Read(b []byte) (int, error) {
n, err := p.r.Read(b)
p.read += int64(n)
if err == io.EOF || time.Since(p.lastEmit) > 100*time.Millisecond {
p.lastEmit = time.Now()
if p.emit != nil {
p.emit(p.read)
}
}
return n, err
}