sak 0.1.1.1 → 0.1.2.0
raw patch · 5 files changed
+49/−10 lines, 5 filesdep +parallel-io
Dependencies added: parallel-io
Files
- CHANGELOG.md +4/−0
- man/sak.1 +4/−0
- sak.cabal +5/−4
- src/Compression.hs +14/−2
- src/Main.hs +22/−4
CHANGELOG.md view
@@ -1,5 +1,9 @@ # sak +## 0.1.2.0++ * Add `matrix` subcommand+ ## 0.1.1.1 * Bundle manpages
man/sak.1 view
@@ -13,6 +13,8 @@ sak transcode tarball.tar.gz tarball.tar.zst .PP sak verify file.gz+.PP+sak matrix release-binary \[en]best .SH SUBCOMMANDS .PP \f[B]compress\f[R] - Compress a file@@ -23,6 +25,8 @@ streaming) .PP \f[B]verify\f[R] - Check the integrity of a compressed file+.PP+\f[B]matrix\f[R] - Generate multiple compressed files in various formats .SH OPTIONS .TP \f[B]-h\f[R] \f[B]--help\f[R]
sak.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: sak-version: 0.1.1.1+version: 0.1.2.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2020 Vanessa McHale@@ -12,7 +12,7 @@ category: CommandLine, Compression build-type: Simple-data-files: man/sak.1+data-files: man/sak.1 extra-source-files: README.md CHANGELOG.md@@ -32,7 +32,7 @@ autogen-modules: Paths_sak default-language: Haskell2010- ghc-options: -Wall+ ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.9 && <5, lzlib >=1.0.1.0,@@ -44,7 +44,8 @@ optparse-applicative -any, filepath -any, bytestring -any,- directory >=1.3.1.0+ directory >=1.3.1.0,+ parallel-io -any if impl(ghc >=8.0) ghc-options:
src/Compression.hs view
@@ -1,4 +1,4 @@-module Compression ( Compression (Lzip)+module Compression ( Compression (Lzma,Lz4,Lzip) , CompressionLevel (..) , detectCompression , toCompressor@@ -6,6 +6,7 @@ , toFileDecompressor , uncompressedExt , check+ , ext -- * Utilities , fileSize ) where@@ -31,10 +32,21 @@ | Lzip | BZip | GZip- | Z | Zstd | Lz4+ | Z | None+ deriving (Enum)++ext :: Compression -> String+ext Lzma = ".xz"+ext Lzip = ".lz"+ext BZip = ".bz2"+ext GZip = ".gz"+ext Zstd = ".zst"+ext Lz4 = ".lz4"+ext Z = ".Z"+ext None = "" uncompressedExt :: FilePath -> FilePath uncompressedExt fp | ".tlz" `isSuffixOf` fp = fp -<.> ".tar"
src/Main.hs view
@@ -3,11 +3,12 @@ module Main ( main ) where import Compression-import qualified Data.ByteString.Lazy as BSL-import Data.Semigroup ((<>))+import Control.Concurrent.ParallelIO.Global (parallel_, stopGlobalPool)+import qualified Data.ByteString.Lazy as BSL+import Data.Semigroup ((<>)) import Options.Applicative-import System.Directory (getSymbolicLinkTarget, pathIsSymbolicLink)-import Version (allVersionsString)+import System.Directory (getSymbolicLinkTarget, pathIsSymbolicLink)+import Version (allVersionsString) reifyPath :: FilePath -> IO FilePath reifyPath fp = do@@ -20,6 +21,7 @@ | Compress !FilePath !FilePath !CompressionLevel | Transcode !FilePath !FilePath !CompressionLevel | Verify !FilePath+ | Matrix !FilePath !CompressionLevel decompressFile :: FilePath -- ^ Compressed file -> FilePath -- ^ Output@@ -34,6 +36,13 @@ compressFile lvl inp o = BSL.writeFile o =<< f inp where f = toFileCompressor (detectCompression o) lvl +compressMatrix :: CompressionLevel+ -> FilePath+ -> Compression+ -> IO ()+compressMatrix lvl inp c =+ BSL.writeFile (inp ++ ext c) =<< toFileCompressor c lvl inp+ run :: Command -> IO () run (Decompress i Nothing) = flip decompressFile (uncompressedExt i) =<< reifyPath i run (Decompress i (Just o)) = flip decompressFile o =<< reifyPath i@@ -45,6 +54,9 @@ _ -> pure Nothing BSL.writeFile o . toCompressor cO lvl guessSz =<< toFileDecompressor (detectCompression i) =<< reifyPath i run (Verify i) = check (detectCompression i) =<< BSL.readFile =<< reifyPath i+run (Matrix inp lvl) =+ parallel_ (compressMatrix lvl inp <$> [Lzma .. Lz4]) *>+ stopGlobalPool fileCompletions :: HasCompleter f => Mod f a fileCompletions = completer (bashCompleter "file -o plusdirs")@@ -95,6 +107,11 @@ outFile :: Parser FilePath outFile = fileHelp "Decompressed output" +matrix :: Parser Command+matrix = Matrix+ <$> fileHelp "File to compress"+ <*> compressionLevel+ compress :: Parser Command compress = Compress <$> fileHelp "File to compress"@@ -114,6 +131,7 @@ <> command "compress" (info compress (progDesc "Compress a file")) <> command "transcode" (info transcode (progDesc "Convert a file's compression")) <> command "verify" (info verify (progDesc "Check the integrity of a compressed file"))+ <> command "matrix" (info matrix (progDesc "Compress a file to all available formats")) ) versionMod :: Parser (a -> a)