mirror of https://github.com/schollz/croc.git
better marshaling
This commit is contained in:
parent
7f0b919b0b
commit
efa66f7cbe
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -223,13 +224,13 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
|||
return err
|
||||
}
|
||||
|
||||
var bl models.BytesAndLocation
|
||||
err = json.Unmarshal(decrypted, &bl)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
// get location if TCP
|
||||
var locationToWrite int
|
||||
if !useWebsockets {
|
||||
pieces := bytes.SplitN(decrypted, []byte("-"), 2)
|
||||
decrypted = pieces[1]
|
||||
locationToWrite, _ = strconv.Atoi(string(pieces[0]))
|
||||
}
|
||||
decrypted = bl.Bytes
|
||||
|
||||
// do decompression
|
||||
if fstats.IsCompressed && !fstats.IsDir {
|
||||
|
@ -242,7 +243,7 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
|||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
n, err = f.WriteAt(decrypted, bl.Location)
|
||||
n, err = f.WriteAt(decrypted, int64(locationToWrite))
|
||||
} else {
|
||||
// write to file
|
||||
n, err = f.Write(decrypted)
|
||||
|
|
|
@ -189,19 +189,13 @@ func send(forceSend int, serverAddress string, tcpPorts []string, isLocal bool,
|
|||
compressedBytes = buffer[:bytesread]
|
||||
}
|
||||
|
||||
// put number of byte read
|
||||
transferBytes, err := json.Marshal(models.BytesAndLocation{Bytes: compressedBytes, Location: currentPostition})
|
||||
if err != nil {
|
||||
dataChan <- DataChan{
|
||||
b: nil,
|
||||
bytesRead: 0,
|
||||
err: err,
|
||||
}
|
||||
return
|
||||
// if using TCP, prepend the location to write the data to in the resulting file
|
||||
if !useWebsockets {
|
||||
compressedBytes = append([]byte(fmt.Sprintf("%d-", currentPostition)), compressedBytes...)
|
||||
}
|
||||
|
||||
// do encryption
|
||||
enc := crypt.Encrypt(transferBytes, sessionKey, !useEncryption)
|
||||
enc := crypt.Encrypt(compressedBytes, sessionKey, !useEncryption)
|
||||
encBytes, err := json.Marshal(enc)
|
||||
if err != nil {
|
||||
dataChan <- DataChan{
|
||||
|
|
Loading…
Reference in New Issue