potoki 0.10 → 0.10.1
raw patch · 3 files changed
+30/−15 lines, 3 files
Files
- library/Potoki/Fetch.hs +7/−2
- library/Potoki/Produce.hs +21/−11
- potoki.cabal +2/−2
library/Potoki/Fetch.hs view
@@ -14,8 +14,13 @@ {-# INLINABLE handleBytes #-}-handleBytes :: Handle -> Int -> Fetch (Either IOException ByteString)-handleBytes handle chunkSize =+handleBytes :: Handle -> Fetch (Either IOException ByteString)+handleBytes =+ handleBytesWithChunkSize ioChunkSize++{-# INLINABLE handleBytesWithChunkSize #-}+handleBytesWithChunkSize :: Int -> Handle -> Fetch (Either IOException ByteString)+handleBytesWithChunkSize chunkSize handle = Fetch $ \ nil just -> do chunk <- try (D.hGetSome handle chunkSize) case chunk of
library/Potoki/Produce.hs view
@@ -8,6 +8,7 @@ fileBytes, fileBytesAtOffset, fileText,+ stdinBytes, directoryContents, finiteMVar, infiniteMVar,@@ -58,13 +59,7 @@ {-# INLINABLE fileBytes #-} fileBytes :: FilePath -> Produce (Either IOException ByteString) fileBytes path =- Produce $ do- handleOpened <- try (openBinaryFile path ReadMode)- case handleOpened of- Right handle ->- return (A.handleBytes handle ioChunkSize, catchIOError (hClose handle) (const (return ())))- Left exception ->- return (pure (Left exception), return ())+ accessingHandle (openBinaryFile path ReadMode) A.handleBytes {-| Read from a file by path.@@ -75,15 +70,30 @@ {-# INLINABLE fileBytesAtOffset #-} fileBytesAtOffset :: FilePath -> Int -> Produce (Either IOException ByteString) fileBytesAtOffset path offset =- Produce (catchIOError success failure)+ accessingHandle acquire A.handleBytes where- success =+ acquire = do handle <- openBinaryFile path ReadMode hSeek handle AbsoluteSeek (fromIntegral offset)- return (A.handleBytes handle ioChunkSize, catchIOError (hClose handle) (const (return ())))- failure exception =+ return handle++{-# INLINABLE accessingHandle #-}+accessingHandle :: IO Handle -> (Handle -> A.Fetch (Either IOException a)) -> Produce (Either IOException a)+accessingHandle acquireHandle fetch =+ Produce (catchIOError normal failing)+ where+ normal =+ do+ handle <- acquireHandle+ return (fetch handle, catchIOError (hClose handle) (const (return ())))+ failing exception = return (pure (Left exception), return ())++{-# INLINABLE stdinBytes #-}+stdinBytes :: Produce (Either IOException ByteString)+stdinBytes =+ Produce (return (A.handleBytes stdin, return ())) {-| Sorted subpaths of the directory.
potoki.cabal view
@@ -1,7 +1,7 @@ name: potoki version:- 0.10+ 0.10.1 synopsis: Simple streaming in IO description:@@ -42,7 +42,7 @@ author: Nikita Volkov <nikita.y.volkov@mail.ru> maintainer:- Metrix.AI Tech Team <tech@metrix.ai>+ Metrix.AI Ninjas <ninjas@metrix.ai> copyright: (c) 2017, Metrix.AI license: