Add file type info detection

This commit is contained in:
2022-01-14 10:06:55 +10:30
parent 1779291586
commit dfe99f4ddb
4 changed files with 24 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ import (
"net"
"os"
"github.com/h2non/filetype"
"github.com/tardisx/netgiv/secure"
)
@@ -52,23 +53,17 @@ func (c *Client) Connect() error {
panic(err)
}
data := secure.PacketSendDataStart{
Filename: "foobar",
TotalSize: 3,
}
err = enc.Encode(data)
if err != nil {
panic(err)
}
log.Print("done that")
nBytes, nChunks := int64(0), int64(0)
reader := bufio.NewReader(os.Stdin)
buf := make([]byte, 0, 1024)
startSent := false
for {
n, err := reader.Read(buf[:cap(buf)])
buf = buf[:n]
if n == 0 {
if err == nil {
continue
@@ -80,7 +75,21 @@ func (c *Client) Connect() error {
}
nChunks++
nBytes += int64(len(buf))
// process buf
if !startSent {
kind, _ := filetype.Match(buf)
data := secure.PacketSendDataStart{
Filename: "foobar",
TotalSize: 3,
Kind: kind.MIME.Value,
}
err = enc.Encode(data)
if err != nil {
panic(err)
}
log.Print("done that")
startSent = true
}
send := secure.PacketSendDataNext{
Size: 5000,
@@ -97,15 +106,6 @@ func (c *Client) Connect() error {
conn.Close()
break
// response := make([]byte, 1024)
// _, err = secureConnection.Read(response)
// if err != nil {
// fmt.Print("Connection to the server was closed.\n")
// break
// }
// fmt.Printf("%s\n", response)
}
return nil