Skip to content

Commit

Permalink
getFileSize
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Jul 25, 2014
1 parent f5da4de commit 00e5700
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions System/EasyFile.hs
Expand Up @@ -74,6 +74,8 @@ module System.EasyFile (
, getChangeTime
, getModificationTime
, getAccessTime
-- * Size
, getFileSize
-- * File\/directory information
, isSymlink
, getLinkCount
Expand Down
14 changes: 14 additions & 0 deletions System/EasyFile/Missing.hs
Expand Up @@ -7,7 +7,9 @@ module System.EasyFile.Missing where
import Control.Applicative
import Data.Time
import Data.Time.Clock.POSIX
import Data.Word (Word64)
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
import Control.Exception
import System.Win32.File
import System.Win32.Time
#else
Expand Down Expand Up @@ -149,3 +151,15 @@ filetimeToUTCTime (FILETIME x) = posixSecondsToUTCTime . realToFrac $ tm
epochTimeToUTCTime :: EpochTime -> UTCTime
epochTimeToUTCTime = posixSecondsToUTCTime . realToFrac
#endif

-- | Getting the size of the file.
getFileSize :: FilePath -> IO Word64
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
getFileSize file = bracket setup teardown body
where
setup = createFile file gENERIC_READ fILE_SHARE_READ Nothing oPEN_EXISTING fILE_ATTRIBUTE_NORMAL Nothing
teardown = closeHandle
body fh = fromIntegral . bhfiSize <$> getFileInformationByHandle fh
#else
getFileSize file = fromIntegral . fileSize <$> getFileStatus file
#endif

0 comments on commit 00e5700

Please sign in to comment.