hpath-directory 0.14.0 → 0.14.1
raw patch · 5 files changed
+61/−4 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Posix.RawFilePath.Directory: readFileStrict :: RawFilePath -> IO ByteString
Files
- CHANGELOG.md +4/−0
- hpath-directory.cabal +1/−1
- src/System/Posix/RawFilePath/Directory.hs +18/−1
- test/System/Posix/RawFilePath/Directory/ReadFileSpec.hs +33/−0
- test/Utils.hs +5/−2
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for hpath-directory +## 0.14.1 -- ????-??-??++- add `readFileStrict`+ ## 0.14.0 -- 2020-07-04 * Fix `readFile` to do proper lazy IO
hpath-directory.cabal view
@@ -1,7 +1,7 @@ cabal-version: >=1.10 name: hpath-directory-version: 0.14.0+version: 0.14.1 synopsis: Alternative to 'directory' package with ByteString based filepaths description: This provides a safer alternative to the 'directory' package. FilePaths are ByteString based, so this
src/System/Posix/RawFilePath/Directory.hs view
@@ -60,6 +60,7 @@ , moveFile -- * File reading , readFile+ , readFileStrict , readFileStream -- * File writing , writeFile@@ -881,7 +882,23 @@ SL.fromChunksIO stream --- | Open the given file as a filestream. Once the filestream is+-- |Read the given file strictly into memory.+--+-- Symbolic links are followed. File must exist.+--+-- Throws:+--+-- - `InappropriateType` if file is not a regular file or a symlink+-- - `PermissionDenied` if we cannot read the file or the directory+-- containting it+-- - `NoSuchThing` if the file does not exist+readFileStrict :: RawFilePath -> IO BS.ByteString+readFileStrict path = do+ stream <- readFileStream path+ fmap fromArray $ S.foldr (<>) mempty stream+++-- | Open the given file as a filestream. Once the filestream -- exits, the filehandle is cleaned up. -- -- Throws:
test/System/Posix/RawFilePath/Directory/ReadFileSpec.hs view
@@ -54,6 +54,38 @@ describe "System.Posix.RawFilePath.Directory.readFile" $ do -- successes --+ it "readFile file with content, everything clear" $ do+ out <- readFileL "fileWithContent"+ out `shouldBe` "Blahfaselgagaga"++ it "readFile symlink, everything clear" $ do+ out <- readFileL "inputFileSymL"+ out `shouldBe` "Blahfaselgagaga"++ it "readFile empty file, everything clear" $ do+ out <- readFileL "fileWithoutContent"+ out `shouldBe` ""+++ -- posix failures --+ it "readFile directory, wrong file type" $ do+ readFileL "alreadyExistsD"+ `shouldThrow` (\e -> ioeGetErrorType e == InappropriateType)++ it "readFile file, no permissions" $ do+ readFileL "noPerms"+ `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied)++ it "readFile file, no permissions on dir" $ do+ readFileL "noPermsD/inputFile"+ `shouldThrow` (\e -> ioeGetErrorType e == PermissionDenied)++ it "readFile file, no such file" $ do+ readFileL "lalala"+ `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing)+++ -- successes -- it "readFile (Strict) file with content, everything clear" $ do out <- readFile' "fileWithContent" out `shouldBe` "Blahfaselgagaga"@@ -83,3 +115,4 @@ it "readFile (Strict) file, no such file" $ do readFile' "lalala" `shouldThrow` (\e -> ioeGetErrorType e == NoSuchThing)+
test/Utils.hs view
@@ -41,7 +41,6 @@ ( ByteString )-import qualified Data.ByteString.Lazy as L import System.Posix.FilePath import System.Posix.Files.ByteString (@@ -289,5 +288,9 @@ readFile' :: ByteString -> IO ByteString {-# NOINLINE readFile' #-}-readFile' p = withTmpDir p (fmap L.toStrict . readFile)+readFile' p = withTmpDir p readFileStrict ++readFileL :: ByteString -> IO BSL.ByteString+{-# NOINLINE readFileL #-}+readFileL p = withTmpDir p readFile