code: function flush(writeTo) {
      var outputTo = bufferLen + matchStart - chunkLength;
  
      while (outputTo > 0 && outputTo > bufferStart) {
        if (outputTo > buffer[0].length-1) {
          var part = buffer.shift();
          outputBuffer.push(part.slice(bufferStart));
  
          bufferStart = Math.max(0, bufferStart - part.length);
          bufferLen -= part.length;
          outputTo -= part.length;
        } else {
          outputBuffer.push(buffer[0].slice(bufferStart, outputTo));
          bufferStart = outputTo;
          break;
        }
      }
      if (writeTo) {
        // Output everything ready as one chunk
        writeTo.push(outputBuffer.join(''));
        outputBuffer.length = 0;
      }
    }
docs: Flush up to the current matchStart (match start is relative to the start of the current chunk so it's negative counting from the end of the buffer)