zrepl/scratchpad/chunker/main.go

85 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
2017-04-26 20:25:53 +02:00
"flag"
"github.com/zrepl/zrepl/sshbytestream"
2017-05-14 15:58:33 +02:00
. "github.com/zrepl/zrepl/util"
// "bytes"
_ "bufio"
// "strings"
2017-04-26 20:25:53 +02:00
"io"
"log"
"os"
2017-04-26 20:25:53 +02:00
_ "time"
)
func main() {
mode := flag.String("mode", "", "incoming|outgoing")
incomingFile := flag.String("incoming.file", "", "file to deliver to callers")
outgoingHost := flag.String("outgoing.sshHost", "", "ssh host")
outgoingUser := flag.String("outgoing.sshUser", "", "ssh user")
outgoingIdentity := flag.String("outgoing.sshIdentity", "", "ssh private key")
outgoingPort := flag.Uint("outgoing.sshPort", 22, "ssh port")
outgoingFile := flag.String("outgoing.File", "", "")
flag.Parse()
switch {
case (*mode == "incoming"):
conn, err := sshbytestream.Incoming()
if err != nil {
panic(err)
}
file, err := os.Open(*incomingFile)
if err != nil {
panic(err)
}
2017-05-14 15:58:33 +02:00
chunker := NewChunker(file)
_, err = io.Copy(conn, &chunker)
if err != nil && err != io.EOF {
panic(err)
}
log.Printf("Chunk Count: %d\n", chunker.ChunkCount)
case *mode == "outgoing":
conn, err := sshbytestream.Outgoing(sshbytestream.SSHTransport{
Host: *outgoingHost,
User: *outgoingUser,
IdentityFile: *outgoingIdentity,
Port: uint16(*outgoingPort),
})
if err != nil {
panic(err)
}
2017-05-12 20:15:27 +02:00
f, err := os.OpenFile(*outgoingFile, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
2017-05-14 15:58:33 +02:00
unchunker := NewUnchunker(conn)
_, err = io.Copy(f, unchunker)
if err != nil {
panic(err)
}
conn.Close()
log.Printf("Chunk Count: %d\n", unchunker.ChunkCount)
os.Exit(0)
default:
panic("unsupported mode!")
}
2017-04-26 20:25:53 +02:00
}