@@ -34,15 +34,12 @@ // 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) - goto write + data, blockSize, bufferLength = ctx.input, len(ctx.input), 0 } // 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 @@ -72,19 +69,12 @@ 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) @@ -93,10 +83,11 @@ 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 }