Fix buffer rewind at end of transmission

Change-Id: I5abb90153931574acf0df5e95e5b286c883539e5
diff --git a/datok.go b/datok.go
index f804bf0..7e5a36d 100644
--- a/datok.go
+++ b/datok.go
@@ -951,6 +951,15 @@
 			}
 		}
 
+		if eot {
+			eot = false
+			textEnd = true
+			w.TextEnd(0)
+			if DEBUG {
+				fmt.Println("END OF TEXT")
+			}
+		}
+
 		// Rewind the buffer if necessary
 		if rewindBuffer {
 
@@ -976,15 +985,6 @@
 			}
 		}
 
-		if eot {
-			eot = false
-			textEnd = true
-			w.TextEnd(0)
-			if DEBUG {
-				fmt.Println("END OF TEXT")
-			}
-		}
-
 		// Move to representative state
 		if ta.isSeparate() {
 			t = ta.getBase()