diff --git a/src/recipient/recipient.go b/src/recipient/recipient.go index b6db4c9..6685f51 100644 --- a/src/recipient/recipient.go +++ b/src/recipient/recipient.go @@ -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) diff --git a/src/sender/sender.go b/src/sender/sender.go index c78a6b3..521edf9 100644 --- a/src/sender/sender.go +++ b/src/sender/sender.go @@ -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{