stats :: Handle -> IO (H.HashMap S.ByteString S.ByteString)
stats h = loop H.empty
  where
    loop m = do
        sendRequest opStat "" 0 nop 0 nop 0 (CAS 0) h
        peekResponse (success m) throwIO h

    success m p = getTotalLength p >>= \tl ->
        if tl == 0
            then return m
            else do
                kl <- getKeyLength p
                k  <- S.hGet h (fromIntegral kl)
                v  <- S.hGet h (fromIntegral tl - fromIntegral kl)
                loop (H.insert k v m)
stats :: Handle -> IO (H.HashMap S.ByteString S.ByteString)
stats h = loop H.empty
  where
    loop m = do
        sendRequest opStat "" 0 nop 0 nop 0 (CAS 0) h
        peekResponse (success m) throwIO h

    success m p = getTotalLength p >>= \tl ->
        if tl == 0
            then return m
            else do
                kl <- getKeyLength p
                k  <- S.hGet h (fromIntegral kl)
                v  <- S.hGet h (fromIntegral tl - fromIntegral kl)
                loop (H.insert k v m)
stats h = loop H.empty
  where
    loop m = do
        sendRequest opStat "" 0 nop 0 nop 0 (CAS 0) h
        peekResponse (success m) throwIO h

    success m p = getTotalLength p >>= \tl ->
        if tl == 0
            then return m
            else do
                kl <- getKeyLength p
                k  <- S.hGet h (fromIntegral kl)
                v  <- S.hGet h (fromIntegral tl - fromIntegral kl)
                loop (H.insert k v m)