asif-3.3.4

Safe HaskellNone
LanguageHaskell2010

Arbor.File.Format.Asif.Write

Contents

Description

Functions to make it easier to write ASIF files without needing to deal with raw Handles and ByteStrings too much.

Synopsis

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

Use these to build FoldMs for the types you want to encode. Compose them together using <>.

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.

genericStep :: MonadResource m => (a -> Builder) -> Handle -> a -> m Handle Source #

genericFold :: MonadResource m => (a -> Builder) -> Whatever Format -> (b -> a) -> Text -> FoldM m b [Segment Handle] Source #