         stream.push string[start...i] # push all content up to the character
         if i is string.length - 1
           stream.__slashIndex = -1
-          return
+          return -> done()
         else
           stream.__slashIndex = i # record the index of this character
           start = i + 1 # move next start to this character

class Kevas extends (require 'stream').Transform
  constructor: (options) ->
    super options
    @_parse = opening
    if options?.values?
      values = options.values
      @on 'key', (key, push) ->
        push values[key] if values[key]?

  _transform: (string, encoding, next) ->
    string = string.toString 'utf8' # buffer becomes string, string returns itself
    parse = @_parse
    parse = parse(this, string) while parse?
    next()

  _flush: (done) -> #if @_parse is closing # TODO: log warning about an unclosed tag?
    @push keyOf this if this.__key?.length > 0
    done()

opening = (stream, string) ->
  stream._parse = opening
  start = 0
  for ch,i in string

#  2. kvstream = require('kvstream')
#     stream = kvstream(options)
#  3. stream = require('kvstream') (options)
module.exports = (options) -> new Kevas options
module.exports.Kevas = Kevas
