|
|
@ -31,14 +31,14 @@ func streamFromReaderToWebsocket(websocketConn *websocket.Conn, reader io.Reader
|
|
|
|
out := make([]byte, readerBufferSize)
|
|
|
|
out := make([]byte, readerBufferSize)
|
|
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
_, err := reader.Read(out)
|
|
|
|
n, err := reader.Read(out)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errorChan <- err
|
|
|
|
errorChan <- err
|
|
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
processedOutput := validString(string(out))
|
|
|
|
processedOutput := validString(string(out[:n]))
|
|
|
|
err = websocketConn.WriteMessage(websocket.TextMessage, []byte(processedOutput))
|
|
|
|
err = websocketConn.WriteMessage(websocket.TextMessage, []byte(processedOutput))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
errorChan <- err
|
|
|
|
errorChan <- err
|
|
|
@ -49,7 +49,10 @@ func streamFromReaderToWebsocket(websocketConn *websocket.Conn, reader io.Reader
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func validString(s string) string {
|
|
|
|
func validString(s string) string {
|
|
|
|
if !utf8.ValidString(s) {
|
|
|
|
if utf8.ValidString(s) {
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v := make([]rune, 0, len(s))
|
|
|
|
v := make([]rune, 0, len(s))
|
|
|
|
|
|
|
|
|
|
|
|
for i, r := range s {
|
|
|
|
for i, r := range s {
|
|
|
@ -63,8 +66,5 @@ func validString(s string) string {
|
|
|
|
v = append(v, r)
|
|
|
|
v = append(v, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s = string(v)
|
|
|
|
return string(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|