     it "should be next/last", (done)->
       count = 0
       lastKey = null
+      pageCount = 0
       nextPage = (db, aLastKey, aPageSize, cb)->
-        pageData = {}
-        pageCount = 0
+        pageData = []
         ReadStream db,
           next: aLastKey
           limit: aPageSize

      stream.on "end", ()->
        keys = Object.keys(data)
        assert.equal keys.length, count
        for k,v of data
          assert.ok k % 2 is 1, "key should be odd"
          assert.equal v, allData[k]

          lastKey = aLastKey
        .on "data", (item)->
          item.key.should.be.gt(aLastKey) if aLastKey
          pageData.push item
        .on "error", (err)->
          done(err)
        .on "end", ()->
          pageCount++
          assert.equal pageData.length, aPageSize if pageCount < 50
          cb(pageData) if cb
      runNext = ->
        if lastKey and pageCount <= 50
          nextPage db, lastKey, 2, (data)->
            lastId = (pageCount-1)*2+1
            lastKey.should.be.equal toFixedInt(lastId,2) if lastKey
            if data.length
              data.should.be.deep.equal [
                {key: toFixedInt(lastId-1), value: allData[toFixedInt(lastId-1)]}
                {key: toFixedInt(lastId), value: allData[toFixedInt(lastId)]}
              ]
            else
              pageCount.should.be.equal 51
              should.not.exist lastKey
            runNext()
        else
          pageCount.should.be.equal 51
          should.not.exist lastKey
          done()
      nextPage db, lastKey, 2, (data)->
        lastId = (pageCount-1)*2+1
        #console.log "p=",pageCount, toFixedInt(lastId,2), lastKey
        lastKey.should.be.equal toFixedInt(lastId,2)
        data.should.be.deep.equal [
          {key: toFixedInt(lastId-1), value: allData[toFixedInt(lastId-1)]}
          {key: toFixedInt(lastId), value: allData[toFixedInt(lastId)]}
        ]
        runNext()

