1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Read blobs from a directory

This commit is contained in:
joshvera 2017-10-17 12:48:27 -04:00
parent 1e267ecc88
commit d2f2764c26
2 changed files with 10 additions and 1 deletions

View File

@ -98,6 +98,7 @@ library
, free
, freer-cofreer
, gitrev
, Glob
, hashable
, kdt
, mersenne-random-pure64

View File

@ -1,8 +1,9 @@
{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, DeriveAnyClass, DuplicateRecordFields, ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, DeriveAnyClass, DuplicateRecordFields, ScopedTypeVariables, TupleSections #-}
module Files
( readFile
, readBlobPairsFromHandle
, readBlobsFromHandle
, readBlobsFromDir
, languageForFilePath
) where
@ -25,6 +26,7 @@ import Prelude hiding (readFile)
import System.Exit
import System.FilePath
import System.IO (Handle)
import System.FilePath.Glob
import Text.Read
-- | Read a utf8-encoded file to a 'Blob'.
@ -51,6 +53,12 @@ readBlobsFromHandle :: MonadIO m => Handle -> m [Blob.Blob]
readBlobsFromHandle = fmap toBlobs . readFromHandle
where toBlobs BlobParse{..} = fmap toBlob blobs
readBlobsFromDir :: MonadIO m => FilePath -> m [Blob.Blob]
readBlobsFromDir path = do
paths <- liftIO (glob (path </> "**/*.rb"))
let paths' = catMaybes $ fmap (\p -> (p,) . Just <$> languageForFilePath p) paths
traverse (uncurry readFile) paths'
readFromHandle :: (FromJSON a, MonadIO m) => Handle -> m a
readFromHandle h = do
input <- liftIO $ BL.hGetContents h