codec-rpm-0.1.3: A library for manipulating RPM files

Copyright(c) 2016-2017 Red Hat Inc.
Safe HaskellNone



A module for creating RPM records from various data sources.



parseRPM :: Parser RPM Source #

A parser (in the attoparsec sense of the term) that constructs RPM records. The parser can be run against a ByteString of RPM data using any of the usual functions. parse and parseOnly are especially useful:

import Data.Attoparsec.ByteString(parse)
import qualified Data.ByteString as BS
s <- BS.readFile "some.rpm"
result <- parse parseRPM s

The Result can then be examined directly or converted using maybeResult (for converting it into a Maybe RPM) or eitherResult (for converting it into an Either String RPM). In the latter case, the String contains any parse error that occurred when reading the RPM data.

parseRPMC :: MonadError String m => Conduit ByteString m RPM Source #

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 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.