1. Aleksey Khudyakov
  2. lackage

Commits

Aleksey Khudyakov  committed 3cc8b33

Hopefully fix problem with lazy IO

  • Participants
  • Parent commits 415910f
  • Branches default

Comments (0)

Files changed (1)

File lackage.hs

View file
  • Ignore whitespace
+import qualified Data.ByteString      as B
 import qualified Data.ByteString.Lazy as L
 
 import Data.List
           "-" -> L.getContents
           _   -> L.readFile tarball
   -- Retrieve cabal file
-  let cabal = getCabal $ Tar.read $ decompress bs
+  let cabal = getCabal $ Tar.read $ decompress $ forceBS bs
       descr = getDescription cabal
   -- Build pathes
   let pkg              = package $ packageDescription descr
 
 -- | Read compressed tarball
 readTar :: FilePath -> IO [Entry]
-readTar path = withFile path ReadMode hreadTar
+readTar path = do 
+  bs <- L.readFile path
+  return $ unpackTar $ forceBS bs
+--   withFile path ReadMode hreadTar
 
 -- | Read compressed tarball from file handle
 hreadTar :: Handle -> IO [Entry]
-hreadTar h = unpackTar `fmap` L.hGetContents h
+hreadTar h = (unpackTar . forceBS) `fmap` L.hGetContents h
 
 unpackTar :: L.ByteString -> [Entry]
 unpackTar 
   case parsePackageDescription $ unpack $ decodeUtf8With lenientDecode cabal of
     ParseOk _ x -> x
     err         -> error $ "Invalid cabal file: " ++ show err
+
+
+forceBS :: L.ByteString -> L.ByteString
+forceBS lazy = L.fromChunks [bs `seq` bs]
+  where
+    bs = B.concat $ L.toChunks lazy