module.exports = function (stream) {
  var ended = false
  var data = null
  var err = null
  var destroyed = false
  var fn = null

  var consume = function (e) {
    if (e) {
      destroyed = true
      if (stream.destroy) stream.destroy(e)
      return
    }

    data = null
    err = null
  }

  var onresult = function () {
    if (!fn) return
    var tmp = fn
    fn = undefined
    tmp(err, data, consume)
  }

  var update = function () {
    if (!fn) return
    data = stream.read()
    if (data === null && !ended) return
    onresult()
  }

  var onend = function () {
    ended = true
    onresult()
  }

  stream.on('readable', update)

  stream.on('error', function (e) {
    err = e
    onresult()
  })

  stream.on('close', function () {
    if (stream._readableState.ended) return
    onend()
  })

  stream.on('end', onend)

  return function (callback) {
    if (destroyed) return
    if (err) return callback(err, null, consume)
    if (data) return callback(null, data, consume)
    if (ended) return callback(null, null, consume)
    fn = callback
    update()
  }
}

@@ -1,8 +1,205 @@
+var Readable = require('stream').Readable%0A%0Avar stream2 = function (stream) %7B%0A  if (stream._readableState) return stream%0A  return new Readable(%7BobjectMode: true, highWaterMark: 16%7D).wrap(stream)%0A%7D%0A%0A
 module.e
@@ -227,16 +227,44 @@
 ream) %7B%0A
+  stream = stream2(stream)%0A%0A
   var en

upgrade streams1 streams