hstar 0.1.0.6 → 0.1.0.7
raw patch · 6 files changed
+56/−22 lines, 6 files
Files
- CHANGELOG.md +4/−0
- README.md +7/−7
- hstar.cabal +11/−11
- man/hstar.1 +2/−2
- src/Compression.cpphs +5/−0
- src/Main.hs +27/−2
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.1.0.7++ * Add `inspect` subcommand+ # 0.1.0.6 * Add `.shar` support
README.md view
@@ -32,13 +32,13 @@ | Program | lzop | lzip | lzma | gzip | bzip2 | zstd | lz4 | brotli | snappy | lrzip | grzip | | ------- | ---- | ---- | ---- | ---- | ----- | ---- | --- | ------ | ------ | ----- | ----- |-| [bsdtar](http://libarchive.org/) | x | x | x | x | x | x | x | | | x | x |-| hstar | x | x | x | x | x | x | x | x | x | ½ | |-| [arc](https://github.com/mholt/archiver) | | | x | x | x | x | ½ | | x | | |-| [Schily tar](http://cdrtools.sourceforge.net/private/star.html) | x | x | x | x | x | x | | | | | |-| [busybox tar](https://www.busybox.net/) | | | x | x | x | | | | | | |-| [python3 tar module](https://docs.python.org/3/library/tarfile.html#command-line-interface) | | | x | x | x | | | | | | |-| [GNU tar](https://www.gnu.org/software/tar/) | x | x | x | x | x | x | | | | | |+| [bsdtar](http://libarchive.org/) | x | x | x | x | x | x | x | | | x | x |+| hstar | x | x | x | x | x | x | x | x | x | ½ | |+| [arc](https://github.com/mholt/archiver) | | | x | x | x | x | ½ | | x | | |+| [Schily tar](http://cdrtools.sourceforge.net/private/star.html) | x | x | x | x | x | x | | | | | |+| [busybox tar](https://www.busybox.net/) | | | x | x | x | | | | | | |+| [python3 tar module](https://docs.python.org/3/library/tarfile.html#command-line-interface) | | | x | x | x | | | | | | |+| [GNU tar](https://www.gnu.org/software/tar/) | x | x | x | x | x | x | | | | | | ## Performance
hstar.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.0 name: hstar-version: 0.1.0.6+version: 0.1.0.7 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2019-2020 Vanessa McHale@@ -32,7 +32,7 @@ executable hstar main-is: Main.hs- build-tool-depends: cpphs:cpphs -any+ build-tool-depends: cpphs:cpphs hs-source-dirs: src other-modules: Compression@@ -53,24 +53,24 @@ build-depends: base >=4.11 && <5, libarchive >=3.0.0.0,- optparse-applicative -any,- composition-prelude -any,- bytestring -any,+ optparse-applicative,+ composition-prelude,+ bytestring, lzma-static, bz2 >=1.0.0.0,- zlib -any,- zstd -any,- lz4-hs >=0.1.1.0,- lzlib >=1.0.1.0,+ zlib,+ zstd,+ lz4-hs >=0.1.4.0,+ lzlib >=1.0.7.0, lzo >=0.1.1.0, process >=1.4.3.0, dir-traverse >=0.2.2.0 if flag(with-snappy)- build-depends: snappy-lazy -any+ build-depends: snappy-lazy if flag(with-brotli)- build-depends: brotli -any+ build-depends: brotli if flag(with-brotli) cpp-options: -DBROTLI
man/hstar.1 view
@@ -1,6 +1,6 @@-.\" Automatically generated by Pandoc 3.1.10+.\" Automatically generated by Pandoc 3.5 .\"-.TH "hstar (1)" "" "" "" ""+.TH "hstar (1)" "" "" "" .SH NAME hstar \- An archiving tool .SH DESCRIPTION
src/Compression.cpphs view
@@ -1,5 +1,6 @@ module Compression ( compressionByFileExt , decompressor+ , archiveDecompressor , compressor ) where @@ -56,6 +57,10 @@ | ".7z" `isSuffixOf` fp = SevenZip | ".zip" `isSuffixOf` fp = Zip | otherwise = error "Suffix not supported or invalid."++archiveDecompressor :: Archive -> (BSL.ByteString -> BSL.ByteString)+archiveDecompressor (Tar c) = decompressor c+archiveDecompressor _ = id decompressor :: Compressor -> (BSL.ByteString -> BSL.ByteString) decompressor Lzma = Lzma.decompress
src/Main.hs view
@@ -1,12 +1,14 @@ module Main ( main ) where -import Codec.Archive (Entry (Entry), EntryContent (Hardlink), entriesToBSL, entriesToBSL7zip, entriesToBSLCpio, entriesToBSLShar,- entriesToBSLzip, readArchiveBSL)+import Codec.Archive (Entry (Entry), EntryContent (..), entriesToBSL, entriesToBSL7zip, entriesToBSLCpio, entriesToBSLShar, entriesToBSLzip,+ readArchiveBSL) import Compression import Compression.Level import Compression.Type import Control.Exception (throw)+import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BSL+import Data.Foldable (traverse_) import Data.Maybe (fromMaybe) import Options.Applicative import Tar@@ -20,6 +22,7 @@ | PackSrc !FilePath !FilePath !CompressionLevel | Sanitize !FilePath !CompressionLevel | Repack !FilePath !FilePath !CompressionLevel+ | Inspect !FilePath forceLast :: [a] -> IO () forceLast = (`seq` mempty) . last@@ -27,6 +30,13 @@ forceBSL :: BSL.ByteString -> IO () forceBSL = forceLast . BSL.toChunks +inspect :: FilePath -> IO ()+inspect fp = do+ let enc = compressionByFileExt fp+ contents <- archiveDecompressor enc <$> BSL.readFile fp+ let es = either throw id $ readArchiveBSL contents+ traverse_ (putStrLn . printEntry) es+ sanitize :: FilePath -> CompressionLevel -> IO () sanitize fp lvl = do let enc = fromArchive $ compressionByFileExt fp@@ -78,6 +88,7 @@ packSrcDirAndCompress (compressionByFileExt tar) lvl dir' tar run (Repack inp out lvl) = repack inp out lvl+run (Inspect fp) = inspect fp sanitizeP :: Parser Command sanitizeP = Sanitize@@ -87,6 +98,13 @@ <> help "Archive to pax-ify") <*> compressionLevel +inspectP :: Parser Command+inspectP = Inspect+ <$> argument str+ (metavar "ARCHIVE"+ <> fileCompletions+ <> help "Archive to open")+ unpack :: Parser Command unpack = Unpack <$> argument str@@ -180,6 +198,7 @@ <> command "pack-src" (info packSrc (progDesc "Pack up a source directory as a bundle, ignoring version control and artifact directories")) <> command "sanitize" (info sanitizeP (progDesc "Sanitize a tar archive so it is pax-compatible")) <> command "repack" (info repackP (progDesc "Convert from one archive format to another"))+ <> command "inspect" (info inspectP (progDesc "Inspect an archive")) ) versionMod :: Parser (a -> a)@@ -193,3 +212,9 @@ main :: IO () main = run =<< execParser topLevel++printEntry :: Entry FilePath BS.ByteString -> String+printEntry (Entry fp Directory _ _ _) = "dir " ++ fp+printEntry (Entry fp (NormalFile bsl) _ _ _) = fp ++ " (" ++ show (BS.length bsl) ++ " bytes)" -- TODO: upstream get size?+printEntry (Entry fp (Symlink fp' _) _ _ _) = fp ++ " -> " ++ fp'+printEntry (Entry fp (Hardlink fp') _ _ _) = fp ++ " link to " ++ fp'