packages feed

sak 0.1.2.0 → 0.1.2.1

raw patch · 4 files changed

+68/−48 lines, 4 filesdep +brotlidep ~lzlib

Dependencies added: brotli

Dependency ranges changed: lzlib

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # sak +## 0.1.2.1++  * Add brotli format support (`.br`)+ ## 0.1.2.0    * Add `matrix` subcommand
man/sak.1 view
@@ -59,6 +59,8 @@ lz4 (0-12) .IP \[bu] 2 deflate (0-9)+.IP \[bu] 2+brotli (0-11) .SH SHELL COMPLETIONS .PP To get shell completions in your current session:
sak.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.18 name:               sak-version:            0.1.2.0+version:            0.1.2.1 license:            BSD3 license-file:       LICENSE copyright:          Copyright: (c) 2020 Vanessa McHale@@ -35,7 +35,7 @@     ghc-options:        -Wall -threaded -rtsopts -with-rtsopts=-N     build-depends:         base >=4.9 && <5,-        lzlib >=1.0.1.0,+        lzlib >=1.0.7.0,         bz2 >=0.1.1.0,         zlib -any,         zstd -any,@@ -45,7 +45,8 @@         filepath -any,         bytestring -any,         directory >=1.3.1.0,-        parallel-io -any+        parallel-io -any,+        brotli -any      if impl(ghc >=8.0)         ghc-options:
src/Compression.hs view
@@ -11,6 +11,7 @@                    , fileSize                    ) where +import qualified Codec.Compression.Brotli    as Br import qualified Codec.Compression.BZip      as BZip import qualified Codec.Compression.GZip      as GZip import qualified Codec.Compression.Lzma      as Lzma@@ -33,20 +34,22 @@                  | BZip                  | GZip                  | Zstd+                 | Brotli                  | 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 = ""+ext Lzma   = ".xz"+ext Lzip   = ".lz"+ext BZip   = ".bz2"+ext GZip   = ".gz"+ext Zstd   = ".zst"+ext Lz4    = ".lz4"+ext Z      = ".Z"+ext Brotli = ".br"+ext None   = ""  uncompressedExt :: FilePath -> FilePath uncompressedExt fp | ".tlz" `isSuffixOf` fp    = fp -<.> ".tar"@@ -59,6 +62,7 @@                    | ".xcfbz2" `isSuffixOf` fp = fp -<.> ".xcf"                    | ".tbz2" `isSuffixOf` fp   = fp -<.> "tar"                    | ".tbz" `isSuffixOf` fp    = fp -<.> "tar"+                   | ".tbr" `isSuffixOf` fp = fp -<.> "tar"                    | otherwise                 = dropExtension fp  detectCompression :: FilePath -> Compression@@ -79,6 +83,7 @@     | ".xcfbz2" `isSuffixOf` fp = BZip     | ".cpgz" `isSuffixOf` fp   = GZip     | ".cpbz2" `isSuffixOf` fp  = BZip+    | ".br" `isSuffixOf` fp     = Brotli     | otherwise                 = None -- error "Suffix not supported or invalid"  toFileDecompressor :: Compression -> FilePath -> IO BSL.ByteString@@ -86,14 +91,15 @@ toFileDecompressor x   = fmap (toDecompressor x) . BSL.readFile  toDecompressor :: Compression -> BSL.ByteString -> BSL.ByteString-toDecompressor Lzma = Lzma.decompress-toDecompressor Lzip = Lzip.decompress-toDecompressor BZip = BZip.decompress-toDecompressor GZip = GZip.decompress-toDecompressor Z    = Zlib.decompress-toDecompressor Zstd = Zstd.decompress-toDecompressor Lz4  = Lz4.decompress-toDecompressor None = id+toDecompressor Lzma   = Lzma.decompress+toDecompressor Lzip   = Lzip.decompress+toDecompressor BZip   = BZip.decompress+toDecompressor GZip   = GZip.decompress+toDecompressor Z      = Zlib.decompress+toDecompressor Zstd   = Zstd.decompress+toDecompressor Lz4    = Lz4.decompress+toDecompressor Brotli = Br.decompress+toDecompressor None   = id  check :: Compression -> BSL.ByteString -> IO () check = (forceBSL .) . toDecompressor@@ -116,36 +122,42 @@ lzmaCompression :: Int -> Lzma.CompressParams lzmaCompression lvl = Lzma.defaultCompressParams { Lzma.compressLevel = toEnum lvl } +brotliCompression :: Int -> Br.CompressParams+brotliCompression lvl = Br.defaultCompressParams { Br.compressLevel = toEnum lvl }+ toInt :: Compression -> CompressionLevel -> Int-toInt Zstd Best       = Zstd.maxCLevel-toInt Zstd Fastest    = 1-toInt Zstd (Custom i) = levelGuard (1, Zstd.maxCLevel) i-toInt Zstd Default    = 3-toInt Lzip Best       = 9-toInt Lzip Fastest    = 0-toInt Lzip (Custom i) = levelGuard (0, 9) i-toInt Lzip Default    = 6-toInt Lzma Best       = 9-toInt Lzma Fastest    = 0-toInt Lzma (Custom i) = levelGuard (0, 9) i-toInt Lzma Default    = 6-toInt BZip Best       = 9-toInt BZip Fastest    = 1-toInt BZip (Custom i) = i-toInt BZip Default    = 7-toInt GZip Best       = 9-toInt GZip Fastest    = 0-toInt GZip (Custom i) = i-toInt GZip Default    = 6-toInt Z Best          = 9-toInt Z Fastest       = 0-toInt Z (Custom i)    = i-toInt Z Default       = 6-toInt Lz4 Best        = Lz4.lZ4HCClevelMax-toInt Lz4 Fastest     = 0-toInt Lz4 (Custom i)  = levelGuard (0, Lz4.lZ4HCClevelMax) i-toInt Lz4 Default     = 0 -- 1?-toInt None _          = error "Internal error."+toInt Brotli Fastest    = fromEnum (minBound :: Br.CompressionLevel)+toInt Brotli (Custom i) = levelGuard (0,11) i+toInt Brotli _          = fromEnum (maxBound :: Br.CompressionLevel)+toInt Zstd Best         = Zstd.maxCLevel+toInt Zstd Fastest      = 1+toInt Zstd (Custom i)   = levelGuard (1, Zstd.maxCLevel) i+toInt Zstd Default      = 3+toInt Lzip Best         = fromEnum (maxBound :: Lzip.CompressionLevel)+toInt Lzip Fastest      = fromEnum (minBound :: Lzip.CompressionLevel)+toInt Lzip (Custom i)   = levelGuard (0, 9) i+toInt Lzip Default      = 6+toInt Lzma Best         = 9+toInt Lzma Fastest      = 0+toInt Lzma (Custom i)   = levelGuard (0, 9) i+toInt Lzma Default      = 6+toInt BZip Best         = 9+toInt BZip Fastest      = 1+toInt BZip (Custom i)   = i+toInt BZip Default      = 7+toInt GZip Best         = 9+toInt GZip Fastest      = 0+toInt GZip (Custom i)   = i+toInt GZip Default      = 6+toInt Z Best            = 9+toInt Z Fastest         = 0+toInt Z (Custom i)      = i+toInt Z Default         = 6+toInt Lz4 Best          = Lz4.lZ4HCClevelMax+toInt Lz4 Fastest       = 0+toInt Lz4 (Custom i)    = levelGuard (0, Lz4.lZ4HCClevelMax) i+toInt Lz4 Default       = 0 -- 1?+toInt None _            = error "Internal error."  toCompressor :: Compression -> CompressionLevel -> Maybe Int -> BSL.ByteString -> BSL.ByteString toCompressor Lzma lvl _         = Lzma.compressWith (lzmaCompression $ toInt Lzma lvl)@@ -156,6 +168,7 @@ toCompressor Z    lvl _         = Zlib.compressWith (zlibCompression $ toInt Z lvl) toCompressor Zstd lvl _         = Zstd.compress (toInt Zstd lvl) toCompressor Lz4  lvl _         = Lz4.compressSz (toInt Lz4 lvl)+toCompressor Brotli lvl _       = Br.compressWith (brotliCompression $ toInt Brotli lvl) toCompressor None _ _           = id  fileSize :: FilePath -> IO Integer