packages feed

riff 0.1.0.0 → 0.2.0.0

raw patch · 9 files changed

+57/−19 lines, 9 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Riff: RiffChunkChild :: RiffId -> [RiffData] -> RiffChunk
+ Data.Riff: RiffChunkChild :: RiffId -> RiffData -> RiffChunk
- Data.Riff: riffData :: RiffChunk -> [RiffData]
+ Data.Riff: riffData :: RiffChunk -> RiffData
- Data.Riff: type RiffData = Word8
+ Data.Riff: type RiffData = ByteString

Files

Data/Riff.hs view
@@ -5,9 +5,33 @@ Maintainer  : robertmassaioli@gmail.com Stability   : experimental -This module was made as a convinience, it's purpose is to aid the manipulation of RIFF files such -that you can both parse them and asseble them. If you wish to just parse or assemble Riff files -then you may be better off just importing Data.Riff.Parse or Data.Riff.Assemble respectively.+The RIFF module allows the parsing of RIFF files in pure Haskell. It was written to be as efficient+and as simple as possible.++You can parse a RIFF file using the methods provided in this module. For example, if you wanted +to parse a RIFF file and print it out then you could:++> main = withRiffFile "path/to/file.riff" print++And that will print the RIFF file, in gory details, to the screen. You can also use this module to+create a RIFF file in pure Haskell starting with a RiffFile and building it up until you are ready +to write it out to a ByteString or Disk. For example, this is how you might construct a RIFF file +to be written out:++> import Data.Riff+> import qualified Data.ByteString.Lazy as BL+> +> riffFile = RiffFile RIFX "EXPL" children+> +> children = +>    [ RiffChunkChild "fst " $ BL.pack [1..11]+>    , RiffChunkChild "snd " $ BL.pack [11..100]+>    ]+> +> main = assembleRiffFile "example.riff" riffFile++As you can see it is a very simple API that lets you write out data into Riff Files. Have a play +around with with the examples until you can see how it works and fits together. -} module Data.Riff (     -- * RIFF File Data Representaion
Data/Riff/Assemble.hs view
@@ -11,14 +11,15 @@ out:  > import Data.Riff->-> riffFile = RiffFile RIFF "EXPL" children+> import qualified Data.ByteString.Lazy as BL > +> riffFile = RiffFile RIFX "EXPL" children+>  > children = ->    [ RiffChunkChild "fst " [1..11]->    , RiffChunkChild "snd " [11..100]+>    [ RiffChunkChild "fst " $ BL.pack [1..11]+>    , RiffChunkChild "snd " $ BL.pack [11..100] >    ]->+>  > main = assembleRiffFile "example.riff" riffFile  As you can see it is a very simple API that lets you write out data into Riff Files. Have a play @@ -79,7 +80,7 @@    putString . safeId . riffChunkId $ chunk    let chunkSize = calculateChunkLength chunk    putSize context chunkSize-   sequence_ $ fmap putWord8 (riffData chunk)+   putLazyByteString . riffData $ chunk    maybeFillBlank chunkSize writeRiffChunk context chunk@(RiffChunkParent _ _) = do    putString "LIST" -- Do not need to pass through safeId, chosen to be correct
Data/Riff/Operations.hs view
@@ -17,6 +17,7 @@  import Data.Riff.RiffData import Data.Riff.InternalUtil+import qualified Data.ByteString.Lazy as BL  -- | This function calculates the size of the RIFF file if it was written out to disk. trueFileSize @@ -38,7 +39,7 @@ calculateChunkLength     :: RiffChunk      -- ^ The RIFF chunk whose size should be calculated.    -> RiffChunkSize  -- ^ The size of the data portion of that chunk no disk.-calculateChunkLength (RiffChunkChild _ chunkData) = fromIntegral $ length chunkData+calculateChunkLength (RiffChunkChild _ chunkData) = fromIntegral $ BL.length chunkData calculateChunkLength (RiffChunkParent _ children) =     idLength + childHeaderLength children + childrenLength children 
Data/Riff/Parse.hs view
@@ -107,7 +107,7 @@             }, size)       else do          -- TODO do we need to consider byte boundaries here?-         riffData <- lift $ getNWords (fromIntegral size)+         riffData <- lift $ getLazyByteString (fromIntegral size)          lift $ skipToWordBoundary size          return (RiffChunkChild             { riffChunkId = id
Data/Riff/RiffData.hs view
@@ -1,11 +1,12 @@ -- | This module is responsible for all of the datatypes that are required around the codebase. module Data.Riff.RiffData where -import Data.Word (Word8, Word32)+import Data.Word (Word32) import Data.Binary.Get (ByteOffset)+import qualified Data.ByteString.Lazy as BL --- | The data in a riff file is just a collection of bytes.-type RiffData = Word8+-- | The data in a riff file is just a stream of bytes.+type RiffData = BL.ByteString  -- | A Riff file is made up exclusively of Riff Chunks and each chunk, as the second piece -- of data in the chunk, contains it's size. The size never includes the first 8 bytes of@@ -21,7 +22,11 @@ type RiffChunkSize = Word32  -- | A RiffId is just a four character string (FourCC). It is usually (but by no means--- always) chosen to be something that is human readable when converted to ASCII. +-- always) chosen to be something that is human readable when converted to ASCII. Please note+-- that attempting to assemble a riff file with a RIFF ID that is not exactly four characters +-- long will result in the RiffId being modified in the output stream to be four characters long.+-- If the ID is too short then it will be padded with space (' ') characters and if it is too long+-- then it will be truncated at four characters. type RiffId = String  -- | Represents an error in the parsing of a Riff File. It contains the location in the@@ -52,7 +57,7 @@ data RiffChunk     = RiffChunkChild       { riffChunkId :: RiffId-      , riffData :: [RiffData]+      , riffData :: RiffData       }    | RiffChunkParent       { riffFormTypeInfo :: RiffId
README.markdown view
@@ -17,6 +17,10 @@ And there are many more. You can even come up with your own data that can be contained inside RIFF. +## Getting the Code++You can just rely upon the library in your cabal files. The [code is on Hackage][3].+ ## Building the Code  To build the code:@@ -47,3 +51,4 @@   [1]: http://www.johnloomis.org/cpe102/asgn/asgn1/riff.zip  [2]: http://en.wikipedia.org/wiki/Resource_Interchange_File_Format+ [3]: http://hackage.haskell.org/package/riff
riff.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.0+version:             0.2.0.0  -- A short (one-line) description of the package. synopsis:            RIFF parser for Haskell@@ -91,6 +91,7 @@   hs-source-dirs: src   main-is:        riff-structure.hs   build-depends:       base >=4.5 && <5.0+                       , bytestring >=0.9 && <1.0                        , riff   default-language:    Haskell2010 
src/riff-convert.hs view
@@ -22,7 +22,7 @@    handleFlags flags extras     handleFlags :: [Flag] -> [String] -> IO ()-handleFlags flags files = do+handleFlags flags files =     if Help `elem` flags       then putStrLn $ usageInfo "riff-convert" options       else sequence_ $ fmap (convert toRifx) files
src/riff-structure.hs view
@@ -7,6 +7,7 @@ import Data.List (intersperse) import Control.Monad (when) import Data.Char (chr)+import qualified Data.ByteString.Lazy.Char8 as BLC  main = do    args <- getArgs@@ -51,7 +52,7 @@    putStr $ " [" ++ showLength chunk ++ "]"    when (printValue context) $ do       putStr ": "-      inQuotes (putStr . fmap (chr . fromIntegral) $ takeWhile (/= 0) value)+      inQuotes (putStr . BLC.unpack . BLC.takeWhile (/= chr 0) $ value)    putNewline printRiffChunk context chunk@(RiffChunkParent typeName children) = do    printWithIndent context "LIST"