Diff

Differences From Artifact [f0ba5a860c]:

To Artifact [0cc123a3c6]:


32
33
34
35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50
32
33
34
35
36
37
38


39

40

41
42
43
44
45
46
47







-
-

-
+
-







		)

		// Force a flush if we are called with no data to write
		if len(data) == 0 {
			if len(ctx.input) == 0 {
				return nil
			}
			data = ctx.input

			// We can't have more than 7 bytes in the buffer so this is safe
			blockSize = len(ctx.input)
			data, blockSize, bufferLength = ctx.input, len(ctx.input), 0
			goto write
		}

		// Check if there are pending bytes in the buffer
		if len(data) < blockSize || bufferLength > 0 {
			// Check whether we have enough bytes for a complete block
			if len(data) > 8-bufferLength {
				// Fill the buffer ...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
67
68
69
70
71
72
73

74







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95







-

-
-
-
-
-
-
-
+












+







			} else {
				// Add the insufficient data to the buffer and return
				ctx.input = append(ctx.input, data...)
				return nil
			}
		}

	write:
		var buf []byte = make([]byte, 1, blockSize+1)

		var blocks int = len(data) / blockSize
		if blocks == 0 {
			blocks++
		}

		for block := 0; block < blocks; block++ {
		for block := 0; block < len(data)/blockSize; block++ {
			for i := 0; i < blockSize; i++ {
				var current byte = data[(block*blockSize)+i]
				if ctx.table[ctx.hash] == current {
					// Guess was right - don't output
					buf[0] |= 1 << uint(i)
				} else {
					// Guess was wrong, output char
					ctx.table[ctx.hash] = current
					buf = append(buf, current)
				}
				ctx.hash = (ctx.hash << 4) ^ uint16(current)
			}

			_, err = writer.Write(buf)
			if err != nil {
				return err
			}

			// Reset the flags and buffer for the next iteration
			buf[0] ^= buf[0]