codec-rpm 0.1.3 → 0.2.0
raw patch · 6 files changed
+72/−35 lines, 6 filesdep +cpio-conduitdep +lzma-conduitPVP ok
version bump matches the API change (PVP)
Dependencies added: cpio-conduit, lzma-conduit
API changes (from Hackage documentation)
- Codec.RPM.Parse: parseRPMC :: MonadError String m => Conduit ByteString m RPM
+ Codec.RPM.Conduit: parseRPMC :: MonadError ParseError m => Conduit ByteString m RPM
+ Codec.RPM.Conduit: payloadC :: Monad m => Conduit RPM m ByteString
+ Codec.RPM.Conduit: payloadContentsC :: MonadResource m => Conduit RPM m Entry
Files
- ChangeLog.md +6/−0
- Codec/RPM/Conduit.hs +57/−0
- Codec/RPM/Parse.hs +1/−28
- codec-rpm.cabal +5/−2
- examples/inspect.hs +1/−1
- examples/unrpm.hs +2/−4
ChangeLog.md view
@@ -1,3 +1,9 @@+## 0.2.0++* Move parseC into a new Conduit module.+* Add payloadC and payloadContentsC.+* parseRPMC should return a ParseError on error.+ ## 0.1.3 * Derive Ord for DepRequirement.
+ Codec/RPM/Conduit.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE FlexibleContexts #-}++-- |+-- Module: Codec.RPM.Conduit+-- Copyright: (c) 2016-2017 Red Hat, Inc.+-- License: LGPL+--+-- Maintainer: https://github.com/weldr+-- Stability: stable+-- Portability: portable+--+-- A module for interacting with an 'RPM' record using conduits.++module Codec.RPM.Conduit(parseRPMC,+ payloadC,+ payloadContentsC)+ where++import Control.Monad.Except(MonadError, throwError)+import Control.Monad.Trans.Resource(MonadResource)+import Conduit((.|), Conduit, awaitForever, yield)+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as C+import Data.Conduit.Attoparsec(ParseError, conduitParserEither)+import Data.Conduit.Lzma(decompress)+import Data.CPIO(Entry, readCPIO)++import Codec.RPM.Parse(parseRPM)+import Codec.RPM.Types(RPM(..))++-- | Like 'parseRPM', but puts the result into a 'Conduit' as an 'Either', containing either a+-- 'ParseError' or an 'RPM'. The result can be extracted with 'Control.Monad.Except.runExceptT',+-- like so:+--+-- > import Conduit((.|), runConduitRes, sourceFile)+-- > import Control.Monad.Except(runExceptT)+-- > result <- runExceptT $ runConduitRes $ sourceFile "some.rpm" .| parseRPMC .| someConsumer+--+-- On success, the 'RPM' record will be passed down the conduit for futher processing or+-- consumption. On error, the rest of the conduit will be skipped and the 'ParseError' will+-- be returned as the result to be dealt with.+parseRPMC :: MonadError ParseError m => Conduit C.ByteString m RPM+parseRPMC =+ conduitParserEither parseRPM .| consumer+ where+ consumer = awaitForever $ either throwError (yield . snd)++-- | Extract the package payload from an 'RPM', returning it in the conduit.+payloadC :: Monad m => Conduit RPM m BS.ByteString+payloadC = awaitForever (yield . rpmArchive)++-- | Extract the package payload from an 'RPM', decompress it, and return each element of+-- the payload as a 'Data.CPIO.Entry'.+payloadContentsC :: MonadResource m => Conduit RPM m Entry+payloadContentsC = payloadC+ .| decompress Nothing+ .| readCPIO
Codec/RPM/Parse.hs view
@@ -20,21 +20,17 @@ parseOneTag, parseSection, #endif- parseRPM,- parseRPMC)+ parseRPM) where #if !MIN_VERSION_base(4,8,0) import Control.Applicative((<$>)) #endif import Control.Monad(void)-import Control.Monad.Except(MonadError, throwError)-import Conduit((.|), Conduit, awaitForever, yield) import Data.Attoparsec.Binary import Data.Attoparsec.ByteString(Parser, anyWord8, count, take, takeByteString, word8) import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as C-import Data.Conduit.Attoparsec(ParseError(..), conduitParserEither) import Data.Maybe(mapMaybe) import Prelude hiding(take) @@ -145,26 +141,3 @@ remainder = (sectionSize . headerSectionHeader) hdr `mod` 8 in if remainder > 0 then fromIntegral $ 8 - remainder else 0---- | Like 'parseRPM', but puts the result into a 'Conduit' as an 'Either', containing either a--- 'ParseError' or an 'RPM'. The result can be extracted with 'Control.Monad.Except.runExceptT',--- like so:------ > import Conduit((.|), runConduitRes, sourceFile)--- > import Control.Monad.Except(runExceptT)--- > result <- runExceptT $ runConduitRes $ sourceFile "some.rpm" .| parseRPMC .| someConsumer------ On success, the 'RPM' record will be passed down the conduit for futher processing or--- consumption. Functions can be written to extract just one element out of the 'RPM' and--- pass it along. For instance:------ > payloadC :: MonadError e m => Conduit RPM m BS.ByteStrin--- > payloadC = awaitForever (yield . rpmArchive)------ On error, the rest of the conduit will be skipped and the 'ParseError' will be returned--- as the result to be dealt with.-parseRPMC :: MonadError String m => Conduit C.ByteString m RPM-parseRPMC =- conduitParserEither parseRPM .| consumer- where- consumer = awaitForever $ either (throwError . errorMessage) (yield . snd)
codec-rpm.cabal view
@@ -1,5 +1,5 @@ name: codec-rpm-version: 0.1.3+version: 0.2.0 synopsis: A library for manipulating RPM files description: This module provides a library for reading RPM files and converting them into useful data structures. There is currently no way to operate in@@ -27,7 +27,8 @@ location: https://github.com/weldr/codec-rpm library- exposed-modules: Codec.RPM.Parse,+ exposed-modules: Codec.RPM.Conduit,+ Codec.RPM.Parse, Codec.RPM.Tags, Codec.RPM.Types, Codec.RPM.Version@@ -41,6 +42,8 @@ conduit >= 1.2.8 && < 1.3, conduit-combinators >= 1.1.0 && < 1.2, conduit-extra >= 1.1.15 && < 1.2,+ cpio-conduit >= 0.7.0 && < 0.8.0,+ lzma-conduit >= 1.1.3.3 && < 1.2, mtl >= 2.2.1 && < 2.3, parsec >= 3.1.11 && < 3.2, pretty >= 1.1.2.0,
examples/inspect.hs view
@@ -20,7 +20,7 @@ import Text.PrettyPrint(render) import Text.PrettyPrint.HughesPJClass(Pretty(pPrint)) -import Codec.RPM.Parse(parseRPMC)+import Codec.RPM.Conduit(parseRPMC) import Codec.RPM.Types(RPM) consumer :: MonadIO m => Consumer RPM m ()
examples/unrpm.hs view
@@ -30,7 +30,7 @@ import System.Exit(exitFailure) import System.FilePath((</>), splitFileName) -import Codec.RPM.Parse(parseRPMC)+import Codec.RPM.Conduit(parseRPMC, payloadContentsC) import Codec.RPM.Types(RPM(..)) -- Grab an RPM from stdin and convert it into a chunked conduit of ByteStrings. This could@@ -73,9 +73,7 @@ result <- runExceptT $ runConduitRes $ getRPM path .| parseRPMC- .| payloadC- .| decompress Nothing- .| readCPIO+ .| payloadContentsC .| DCC.mapM_ (liftIO . writeCpioEntry) either print return result