我想知道如何以最少的开销获取haskell中文件的大小.现在我有以下代码:
getFileSize :: FilePath -> IO Integer
getFileSize x = do
handle <- openFile x ReadMode
size <- hFileSize handle
hClose handle
return size
Run Code Online (Sandbox Code Playgroud)
这似乎很慢.我偶然发现了System.Posix.Files中的getFileStatus,但不知道它是如何工作的 - 至少我在ghci中玩它时只会遇到错误.另外,我不确定这是否适用于Windows(可能不适用).
重申一下:在Haskell中获取文件大小的最佳(和平台无关)方法是什么?