From 362d3a437c16c10d221caeac21e9f685d7ddf3e6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 22 Apr 2017 11:41:54 -0400 Subject: stream the log avoid processing it in memory, and allow parse errors at end to not prevent displaying part of it --- Log.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'Log.hs') diff --git a/Log.hs b/Log.hs index 50c506d..6c45074 100644 --- a/Log.hs +++ b/Log.hs @@ -87,10 +87,7 @@ parseLog = map eitherDecode' . filter (not . L.null) . L.split (fromIntegral (ord '\n')) --- | Throws exception on unparsable log. -loadLog :: FilePath -> IO [Log] -loadLog f = do - parsed <- parseLog <$> L.readFile f - case lefts parsed of - [] -> return (rights parsed) - errs -> error $ unlines errs +-- | Streams a log without loading it all into memory. +-- When lines cannot be parsed, they will be Left. +streamLog :: FilePath -> IO [Either String Log] +streamLog f = parseLog <$> L.readFile f -- cgit v1.2.3