sak-0.1.2.6: src/Detect.hs
module Detect ( detectFileCompression
) where
import Compression
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import Info
firstChunk :: FilePath -> IO BS.ByteString
firstChunk = fmap (go . BSL.toChunks) . BSL.readFile
where go [] = error "Empty file; could not detect compression"
go (x:_) = x
detectFileCompression :: FilePath -> IO Compression
detectFileCompression fp =
case detectCompression fp of
None -> identify <$> firstChunk fp
x -> pure x