mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
use stderr for output
This commit is contained in:
parent
d555a81d30
commit
ebac8beaaa
3 changed files with 39 additions and 0 deletions
37
main.go
37
main.go
|
@ -4,8 +4,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
humanize "github.com/dustin/go-humanize"
|
||||||
"github.com/schollz/croc/src/croc"
|
"github.com/schollz/croc/src/croc"
|
||||||
"github.com/schollz/utils"
|
"github.com/schollz/utils"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -112,6 +114,30 @@ func send(c *cli.Context) error {
|
||||||
// generate code phrase
|
// generate code phrase
|
||||||
codePhrase = utils.GetRandomName()
|
codePhrase = utils.GetRandomName()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print the text
|
||||||
|
finfo, err := os.Stat(fname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, filename := filepath.Split(fname)
|
||||||
|
fileOrFolder := "file"
|
||||||
|
fsize := finfo.Size()
|
||||||
|
if finfo.IsDir() {
|
||||||
|
fileOrFolder = "folder"
|
||||||
|
fsize, err = dirSize(fname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr,
|
||||||
|
"Sending %s %s name '%s'\nCode is: %s\nOn the other computer, please run:\n\ncroc %s",
|
||||||
|
humanize.Bytes(uint64(fsize)),
|
||||||
|
fileOrFolder,
|
||||||
|
filename,
|
||||||
|
codePhrase,
|
||||||
|
codePhrase,
|
||||||
|
)
|
||||||
return cr.Send(fname, codePhrase)
|
return cr.Send(fname, codePhrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,3 +156,14 @@ func relay(c *cli.Context) error {
|
||||||
cr.CurveType = c.String("curve")
|
cr.CurveType = c.String("curve")
|
||||||
return cr.Relay()
|
return cr.Relay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dirSize(path string) (int64, error) {
|
||||||
|
var size int64
|
||||||
|
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||||
|
if !info.IsDir() {
|
||||||
|
size += info.Size()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
return size, err
|
||||||
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ func receive(c *websocket.Conn, codephrase string) (err error) {
|
||||||
int(fstats.Size),
|
int(fstats.Size),
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
progressbar.OptionSetBytes(int(fstats.Size)),
|
progressbar.OptionSetBytes(int(fstats.Size)),
|
||||||
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
)
|
)
|
||||||
c.WriteMessage(websocket.BinaryMessage, []byte("ready"))
|
c.WriteMessage(websocket.BinaryMessage, []byte("ready"))
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -136,6 +136,7 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) {
|
||||||
int(fstats.Size),
|
int(fstats.Size),
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
progressbar.OptionSetBytes(int(fstats.Size)),
|
progressbar.OptionSetBytes(int(fstats.Size)),
|
||||||
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
bytesread, err := f.Read(buffer)
|
bytesread, err := f.Read(buffer)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue