@@ -13,13 +13,15 @@ module Data.Binary.Bits.Get
1313 , getWord32be
1414 , getWord64be
1515
16+ , Data.Binary.Bits.Get.getByteString
17+
1618 , readBool
1719 , readWord8
1820 , readWord16be
1921
2022 ) where
2123
22−import Data.Binary.Get ( runGet, Get, getByteString )
24+import Data.Binary.Get as B ( runGet, Get, getByteString )
2325
2426import Data.ByteString as B
2527import Data.ByteString.Internal
@@ -268,7 +270,7 @@ ensureBits n = C $ \s kf ks ->
268270 | otherwise = do
269271 let currentBits = B.length bs * 8 - o
270272 let byteCount = (n - currentBits + 7) `div` 8
271− bs' <- getByteString byteCount
273+ bs' <- B.getByteString byteCount
272274 -- should always be enough going once throguh the loop
273275 loop (S (bs`append`bs') o)
274276 in loop s
@@ -288,6 +290,15 @@ getWord32be n = ensureBits n >> modifyState (flip readWord32be n)
288290getWord64be :: Int -> BitGet Word64
289291getWord64be n = ensureBits n >> modifyState (flip readWord64be n)
290292
293+getByteString :: Int -> BitGet ByteString
294+getByteString n = do
295+ ensureBits (n*8)
296+ -- drop the first byte if we've started to use it
297+ modifyState $ \s@(S bs o) ->
298+ let bs' | o == 0 = bs
299+ | otherwise = B.tail bs
300+ in B.take n bs' :*: S (B.drop n bs') 0
301+
291302getState :: BitGet S
292303getState = C $ \s kf ks -> ks s s
293304