| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Arbor.File.Format.Asif.Write
Description
Functions to make it easier to write ASIF files without needing to deal with raw Handles and ByteStrings too much.
Synopsis
- writeAsif :: (Foldable f, MonadResource m) => Handle -> String -> Maybe POSIXTime -> FoldM m a [Segment Handle] -> f a -> m ()
- buildAsifBytestring :: (Foldable f, MonadResource m) => String -> Maybe POSIXTime -> FoldM m a [Segment Handle] -> f a -> m ByteString
- lazyByteStringSegment :: MonadResource m => Whatever Format -> (a -> ByteString) -> Text -> FoldM m a [Segment Handle]
- nullTerminatedStringSegment :: MonadResource m => (a -> Text) -> Text -> FoldM m a [Segment Handle]
- textSegment :: MonadResource m => (a -> Text) -> Text -> FoldM m a [Segment Handle]
- asciiSegment :: MonadResource m => (a -> Char) -> Text -> FoldM m a [Segment Handle]
- word8Segment :: MonadResource m => (a -> Word8) -> Text -> FoldM m a [Segment Handle]
- word16Segment :: MonadResource m => (a -> Word16) -> Text -> FoldM m a [Segment Handle]
- word32Segment :: MonadResource m => (a -> Word32) -> Text -> FoldM m a [Segment Handle]
- word64Segment :: MonadResource m => (a -> Word64) -> Text -> FoldM m a [Segment Handle]
- int8Segment :: MonadResource m => (a -> Int8) -> Text -> FoldM m a [Segment Handle]
- int16Segment :: MonadResource m => (a -> Int16) -> Text -> FoldM m a [Segment Handle]
- int32Segment :: MonadResource m => (a -> Int32) -> Text -> FoldM m a [Segment Handle]
- int64Segment :: MonadResource m => (a -> Int64) -> Text -> FoldM m a [Segment Handle]
- ipv4Segment :: MonadResource m => (a -> IPv4) -> Text -> FoldM m a [Segment Handle]
- ipv6Segment :: MonadResource m => (a -> IPv6) -> Text -> FoldM m a [Segment Handle]
- utcTimeMicrosSegment :: MonadResource m => (a -> UTCTime) -> Text -> FoldM m a [Segment Handle]
- genericInitial :: MonadResource m => Text -> m Handle
- genericStep :: MonadResource m => (a -> Builder) -> Handle -> a -> m Handle
- genericExtract :: MonadResource m => Text -> Whatever Format -> Handle -> m [Segment Handle]
- genericFold :: MonadResource m => (a -> Builder) -> Whatever Format -> (b -> a) -> Text -> FoldM m b [Segment Handle]
Encode an entire ASIF bytestring
Facilities for writing an entire ASIF file, either to an actual file or to a ByteString.
- * Usage:
Use the various *segment functions to produce a FoldM. These are designed to
allow you to take some large type (e.g. a tuple or a product type) and pull
out the constituent pieces to encode into
Segments.
FoldMs are composable using <>. Once you have a single, provide it to
writeAsif or buildAsifBytestring along with an appropriate foldable.
Both these functions will stream from the input, assuming the foldable is
something that can be streamed from.
writeAsif :: (Foldable f, MonadResource m) => Handle -> String -> Maybe POSIXTime -> FoldM m a [Segment Handle] -> f a -> m () Source #
Write an ASIF file to the supplied handle. Streams the input foldable if possible.
buildAsifBytestring :: (Foldable f, MonadResource m) => String -> Maybe POSIXTime -> FoldM m a [Segment Handle] -> f a -> m ByteString Source #
Builds a lazy ASIF bytestring. Streams the input foldable if possible.
Folds for Segments
lazyByteStringSegment :: MonadResource m => Whatever Format -> (a -> ByteString) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment from lazy bytestrings. This can in priciple cover any bytestring-y format, including StringZ, Text, Binary, Bitmap, and Bitstring, as well as unknown encodings. Correctly encoding the value is the responsibility of the caller.
nullTerminatedStringSegment :: MonadResource m => (a -> Text) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of null-termianted strings. Note that the input itself does *not* need to be null-terminated. The null-termination is added by this function.
textSegment :: MonadResource m => (a -> Text) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Texts.
asciiSegment :: MonadResource m => (a -> Char) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Chars.
word8Segment :: MonadResource m => (a -> Word8) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Word8s.
word16Segment :: MonadResource m => (a -> Word16) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Word16s.
word32Segment :: MonadResource m => (a -> Word32) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Word32s.
word64Segment :: MonadResource m => (a -> Word64) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Word64s.
int8Segment :: MonadResource m => (a -> Int8) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Int8s.
int16Segment :: MonadResource m => (a -> Int16) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Int16s.
int32Segment :: MonadResource m => (a -> Int32) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Int32s.
int64Segment :: MonadResource m => (a -> Int64) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of Int64s.
ipv4Segment :: MonadResource m => (a -> IPv4) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of IPv4s.
ipv6Segment :: MonadResource m => (a -> IPv6) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of IPv6s.
utcTimeMicrosSegment :: MonadResource m => (a -> UTCTime) -> Text -> FoldM m a [Segment Handle] Source #
Builds a segment of UTCTimes, accurate to microseconds.
Utility functions
Helper functions for creating FoldMs from scratch.
genericInitial :: MonadResource m => Text -> m Handle Source #
genericStep :: MonadResource m => (a -> Builder) -> Handle -> a -> m Handle Source #
genericExtract :: MonadResource m => Text -> Whatever Format -> Handle -> m [Segment Handle] Source #