mirror of
https://github.com/schollz/croc.git
synced 2024-11-27 12:34:19 +03:00
use stderr for output
This commit is contained in:
parent
d555a81d30
commit
ebac8beaaa
37
main.go
37
main.go
@ -4,8 +4,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/schollz/croc/src/croc"
|
||||
"github.com/schollz/utils"
|
||||
"github.com/urfave/cli"
|
||||
@ -112,6 +114,30 @@ func send(c *cli.Context) error {
|
||||
// generate code phrase
|
||||
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)
|
||||
}
|
||||
|
||||
@ -130,3 +156,14 @@ func relay(c *cli.Context) error {
|
||||
cr.CurveType = c.String("curve")
|
||||
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),
|
||||
progressbar.OptionSetRenderBlankState(true),
|
||||
progressbar.OptionSetBytes(int(fstats.Size)),
|
||||
progressbar.OptionSetWriter(os.Stderr),
|
||||
)
|
||||
c.WriteMessage(websocket.BinaryMessage, []byte("ready"))
|
||||
for {
|
||||
|
@ -136,6 +136,7 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) {
|
||||
int(fstats.Size),
|
||||
progressbar.OptionSetRenderBlankState(true),
|
||||
progressbar.OptionSetBytes(int(fstats.Size)),
|
||||
progressbar.OptionSetWriter(os.Stderr),
|
||||
)
|
||||
for {
|
||||
bytesread, err := f.Read(buffer)
|
||||
|
Loading…
Reference in New Issue
Block a user