Permalink
Browse files

pack: add packReadObject; read object at given offset

  • Loading branch information...
1 parent 632c0e2 commit 409992084ddde79b1812cb02c0e08b7e58fb484a @kfish committed May 10, 2011
Showing with 16 additions and 0 deletions.
  1. +16 −0 Git/Pack.hs
View
@@ -11,6 +11,7 @@ module Git.Pack (
-- * Iteratee
packRead,
+ packReadObject,
-- * Paths
packPath
@@ -27,6 +28,7 @@ import Data.Iteratee.ZLib
import Data.Maybe (catMaybes)
import Data.Word
import System.FilePath
+import System.Posix.Types
import Git.Path
@@ -76,6 +78,20 @@ packReader = do
return $ Just (Pack ver num os)
else return Nothing
+packReadObject :: FilePath -> FileOffset -> IO (Maybe PackObject)
+packReadObject fp off = I.fileDriverRandom (packReadObject' off) fp
+
+packReadObject' :: FileOffset -> I.Iteratee ByteString IO (Maybe PackObject)
+packReadObject' off = do
+ n <- I.heads "PACK"
+ if (n == 4)
+ then do
+ _ver <- fromIntegral <$> endianRead4 MSB
+ _num <- fromIntegral <$> endianRead4 MSB
+ I.seek off
+ packObjectRead
+ else return Nothing
+
packObjectRead :: I.Iteratee ByteString IO (Maybe PackObject)
packObjectRead = do
x <- I.head

0 comments on commit 4099920

Please sign in to comment.