1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-10 21:01:02 +02:00

move file processing until after recipient chimes in

This commit is contained in:
Zack Scholl 2018-09-22 06:51:08 -07:00
parent 4d9455c24b
commit 9cf6bdf4a8
3 changed files with 64 additions and 35 deletions

27
main.go
View file

@ -3,6 +3,9 @@ package main
import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
@ -100,7 +103,26 @@ func send(c *cli.Context) error {
stat, _ := os.Stdin.Stat()
var fname string
if (stat.Mode() & os.ModeCharDevice) == 0 {
fname = "stdin"
f, err := ioutil.TempFile(".", "croc-stdin-")
if err != nil {
return err
}
_, err = io.Copy(f, os.Stdin)
if err != nil {
return err
}
err = f.Close()
if err != nil {
return err
}
fname = f.Name()
defer func() {
log.Println("removing %s", fname)
err = os.Remove(fname)
if err != nil {
log.Println(err)
}
}()
} else {
fname = c.Args().First()
}
@ -140,8 +162,7 @@ func send(c *cli.Context) error {
codePhrase,
codePhrase,
)
err = cr.Send(fname, codePhrase)
return err
return cr.Send(fname, codePhrase)
}
func receive(c *cli.Context) error {