sak 0.1.0.2 → 0.1.1.0
raw patch · 3 files changed
+20/−7 lines, 3 filesdep +directory
Dependencies added: directory
Files
- CHANGELOG.md +4/−0
- sak.cabal +3/−2
- src/Main.hs +13/−5
CHANGELOG.md view
@@ -1,5 +1,9 @@ # sak +## 0.1.1.0++ * Support compression through symlinks+ ## 0.1.0.2 * Support higher compression levels for lz4
sak.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: sak-version: 0.1.0.2+version: 0.1.1.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2020 Vanessa McHale@@ -43,7 +43,8 @@ lz4-hs >=0.1.4.0, optparse-applicative -any, filepath -any,- bytestring -any+ bytestring -any,+ directory >=1.3.1.0 if impl(ghc >=8.0) ghc-options:
src/Main.hs view
@@ -6,8 +6,16 @@ import qualified Data.ByteString.Lazy as BSL import Data.Semigroup ((<>)) import Options.Applicative+import System.Directory (getSymbolicLinkTarget, pathIsSymbolicLink) import Version (allVersionsString) +reifyPath :: FilePath -> IO FilePath+reifyPath fp = do+ isSym <- pathIsSymbolicLink fp+ if isSym+ then getSymbolicLinkTarget fp+ else pure fp+ data Command = Decompress !FilePath !(Maybe FilePath) | Compress !FilePath !FilePath !CompressionLevel | Transcode !FilePath !FilePath !CompressionLevel@@ -27,16 +35,16 @@ where f = toFileCompressor (detectCompression o) lvl run :: Command -> IO ()-run (Decompress i Nothing) = decompressFile i (uncompressedExt i)-run (Decompress i (Just o)) = decompressFile i o-run (Compress i o lvl) = compressFile lvl i o+run (Decompress i Nothing) = flip decompressFile (uncompressedExt i) =<< reifyPath i+run (Decompress i (Just o)) = flip decompressFile o =<< reifyPath i+run (Compress i o lvl) = flip (compressFile lvl) o =<< reifyPath i run (Transcode i o lvl) = do let cO = detectCompression o guessSz <- case cO of Lzip -> Just . (8*) . fromIntegral <$> fileSize i _ -> pure Nothing- BSL.writeFile o . toCompressor cO lvl guessSz =<< toFileDecompressor (detectCompression i) i-run (Verify i) = check (detectCompression i) =<< BSL.readFile i+ BSL.writeFile o . toCompressor cO lvl guessSz =<< toFileDecompressor (detectCompression i) =<< reifyPath i+run (Verify i) = check (detectCompression i) =<< BSL.readFile =<< reifyPath i fileCompletions :: HasCompleter f => Mod f a fileCompletions = completer (bashCompleter "file -o plusdirs")