Safe Haskell | None |
---|---|
Language | Haskell98 |
Buffer builder to assemble Bgzf blocks. (This will probably be renamed.) The plan is to serialize stuff (BAM and BCF) into a buffer, then Bgzf chunks from the buffer and reuse it. This should avoid redundant copying and relieve some pressure from the garbage collector. And I hope to plug a mysterious memory leak that doesn't show up in the profiler.
Exported functions with unsafe
in the name resulting in a type of
Push
omit the bounds checking. To use them safely, an appropriate
ensureBuffer
has to precede them.
- data BB = BB {}
- newtype Push = Push (BB -> IO BB)
- newBuffer :: IO BB
- ensureBuffer :: Int -> Push
- expandBuffer :: BB -> IO BB
- unsafePushByte :: Word8 -> Push
- pushByte :: Word8 -> Push
- unsafePushWord32 :: Word32 -> Push
- unsafePushWord16 :: Word16 -> Push
- pushWord32 :: Word32 -> Push
- pushWord16 :: Word16 -> Push
- unsafePushByteString :: ByteString -> Push
- pushByteString :: ByteString -> Push
- pushBuilder :: Builder -> Push
- unsafeSetMark :: Push
- setMark :: Push
- endRecord :: Push
- encodeBgzfWith :: MonadIO m => Int -> Enumeratee Push ByteString m b
Documentation
The MutableByteArray
is garbage collected, so we don't get leaks.
Once it has grown to a practical size (and the initial 128k should be
very practical), we don't get fragmentation either. We also avoid
copies for the most part, since no intermediate ByteString
s, either
lazy or strict have to be allocated.
ensureBuffer :: Int -> Push Source
Ensures a given free space in the buffer by doubling its capacity if necessary.
expandBuffer :: BB -> IO BB Source
unsafePushByte :: Word8 -> Push Source
unsafePushWord32 :: Word32 -> Push Source
unsafePushWord16 :: Word16 -> Push Source
pushWord32 :: Word32 -> Push Source
pushWord16 :: Word16 -> Push Source
pushByteString :: ByteString -> Push Source
pushBuilder :: Builder -> Push Source
Sets a mark. This can later be filled in with a record length (used to create BAM records).
Ends a record by filling the length into the field that was
previously marked. Terrible things will happen if this wasn't
preceded by a corresponding setMark
.
encodeBgzfWith :: MonadIO m => Int -> Enumeratee Push ByteString m b Source