Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faster alternatives to hFileSize to retrieve the size of a file in Haskell?

I am wondering how to get the size of a file in haskell with the least amount of overhead. Right now I have the following code:

getFileSize :: FilePath -> IO Integer
getFileSize x = do
handle <- openFile x ReadMode
size <- hFileSize handle
hClose handle
return size

This seems to be quite slow. I have stumbled across getFileStatus in System.Posix.Files but don't know how it works - at least I only get errors when playing around with it in ghci. Also, I am not sure if this would work on Windows (probably not).

So to reiterate: What is the best (and platform independent) approach to get the size of a file in Haskell?

like image 776
markmywords Avatar asked Apr 11 '11 10:04

markmywords


1 Answers

https://hackage.haskell.org/package/directory-1.3.6.0/docs/System-Directory.html#v:getFileSize

getFileSize :: FilePath -> IO Integer
like image 77
Chris Stryczynski Avatar answered Sep 30 '22 03:09

Chris Stryczynski