ContentsIndex
ByteStringUtils
Portabilityportable
Stabilityexperimental
Maintainerdroundy@abridgegame.org
Description
GZIp and MMap IO for ByteStrings, and miscellaneous functions for Data.ByteString
Synopsis
debugForeignPtr :: ForeignPtr a -> String -> IO ()
unsafeWithInternals :: ByteString -> (Ptr Word8 -> Int -> IO a) -> IO a
readIntPS :: ByteString -> Maybe (Int, ByteString)
unpackPSfromUTF8 :: ByteString -> String
utf8_to_ints :: Ptr Int -> Ptr Word8 -> CInt -> IO CInt
ifHeadThenTail :: Word8 -> ByteString -> Maybe ByteString
isSpaceWord8 :: Word8 -> Bool
firstnonspace :: Ptr Word8 -> Int -> Int -> IO Int
firstspace :: Ptr Word8 -> Int -> Int -> IO Int
dropSpace :: ByteString -> ByteString
breakSpace :: ByteString -> (ByteString, ByteString)
is_funky :: ByteString -> Bool
has_funky_char :: Ptr Word8 -> CInt -> IO CInt
hashPS :: ByteString -> Int32
hash :: Ptr Word8 -> Int -> IO Int32
substrPS :: ByteString -> ByteString -> Maybe Int
breakFirstPS :: Char -> ByteString -> Maybe (ByteString, ByteString)
breakLastPS :: Char -> ByteString -> Maybe (ByteString, ByteString)
linesPS :: ByteString -> [ByteString]
unlinesPS :: [ByteString] -> ByteString
c_gzopen :: CString -> CString -> IO (Ptr ())
c_gzclose :: Ptr () -> IO ()
c_gzread :: Ptr () -> Ptr Word8 -> CInt -> IO CInt
c_gzwrite :: Ptr () -> Ptr Word8 -> CInt -> IO CInt
gzReadFilePS :: FilePath -> IO ByteString
hGetLittleEndInt :: Handle -> IO Int
gzWriteFilePS :: FilePath -> ByteString -> IO ()
gzWriteFilePSs :: FilePath -> [ByteString] -> IO ()
gzWriteToGzf :: Ptr () -> ByteString -> IO ()
mmapFilePS :: FilePath -> IO ByteString
conv_to_hex :: Ptr Word8 -> Ptr Word8 -> CInt -> IO ()
fromPS2Hex :: ByteString -> ByteString
conv_from_hex :: Ptr Word8 -> Ptr Word8 -> CInt -> IO ()
fromHex2PS :: ByteString -> ByteString
betweenLinesPS :: ByteString -> ByteString -> ByteString -> Maybe ByteString
break_after_nth_newline :: Int -> ByteString -> Maybe (ByteString, ByteString)
break_before_nth_newline :: Int -> ByteString -> (ByteString, ByteString)
Documentation
debugForeignPtr :: ForeignPtr a -> String -> IO ()
unsafeWithInternals :: ByteString -> (Ptr Word8 -> Int -> IO a) -> IO a
Do something with the internals of a PackedString. Beware of altering the contents!
readIntPS :: ByteString -> Maybe (Int, ByteString)
readIntPS skips any whitespace at the beginning of its argument, and reads an Int from the beginning of the PackedString. If there is no integer at the beginning of the string, it returns Nothing, otherwise it just returns the int read, along with a B.ByteString containing the remainder of its input.
unpackPSfromUTF8 :: ByteString -> String
utf8_to_ints :: Ptr Int -> Ptr Word8 -> CInt -> IO CInt
ifHeadThenTail :: Word8 -> ByteString -> Maybe ByteString
isSpaceWord8 :: Word8 -> Bool
firstnonspace :: Ptr Word8 -> Int -> Int -> IO Int
firstspace :: Ptr Word8 -> Int -> Int -> IO Int
dropSpace :: ByteString -> ByteString

dropSpace efficiently returns the ByteString argument with white space Chars removed from the front. It is more efficient than calling dropWhile for removing whitespace. I.e.

 dropWhile isSpace == dropSpace
breakSpace :: ByteString -> (ByteString, ByteString)

breakSpace returns the pair of ByteStrings when the argument is broken at the first whitespace byte. I.e.

 break isSpace == breakSpace
is_funky :: ByteString -> Bool
has_funky_char :: Ptr Word8 -> CInt -> IO CInt
hashPS :: ByteString -> Int32
hash :: Ptr Word8 -> Int -> IO Int32
substrPS :: ByteString -> ByteString -> Maybe Int
breakFirstPS :: Char -> ByteString -> Maybe (ByteString, ByteString)
breakLastPS :: Char -> ByteString -> Maybe (ByteString, ByteString)
linesPS :: ByteString -> [ByteString]
unlinesPS :: [ByteString] -> ByteString

This function acts exactly like the Prelude unlines function, or like Data.ByteString.Char8 unlines, but with one important difference: it will produce a string which may not end with a newline! That is:

 unlinesPS ["foo", "bar"]

evaluates to "foo\nbar", not "foo\nbar\n"! This point should hold true for linesPS as well.

TODO: rename this function.

c_gzopen :: CString -> CString -> IO (Ptr ())
Read an entire file, which may or may not be gzip compressed, directly into a ByteString.
c_gzclose :: Ptr () -> IO ()
c_gzread :: Ptr () -> Ptr Word8 -> CInt -> IO CInt
c_gzwrite :: Ptr () -> Ptr Word8 -> CInt -> IO CInt
gzReadFilePS :: FilePath -> IO ByteString
hGetLittleEndInt :: Handle -> IO Int
gzWriteFilePS :: FilePath -> ByteString -> IO ()
gzWriteFilePSs :: FilePath -> [ByteString] -> IO ()
gzWriteToGzf :: Ptr () -> ByteString -> IO ()
mmapFilePS :: FilePath -> IO ByteString
Like readFilePS, this reads an entire file directly into a ByteString, but it is even more efficient. It involves directly mapping the file to memory. This has the advantage that the contents of the file never need to be copied. Also, under memory pressure the page may simply be discarded, wile in the case of readFilePS it would need to be written to swap. If you read many small files, mmapFilePS will be less memory-efficient than readFilePS, since each mmapFilePS takes up a separate page of memory. Also, you can run into bus errors if the file is modified. NOTE: as with readFilePS, the string representation in the file is assumed to be ISO-8859-1.
conv_to_hex :: Ptr Word8 -> Ptr Word8 -> CInt -> IO ()
fromPS2Hex :: ByteString -> ByteString
conv_from_hex :: Ptr Word8 -> Ptr Word8 -> CInt -> IO ()
fromHex2PS :: ByteString -> ByteString
betweenLinesPS :: ByteString -> ByteString -> ByteString -> Maybe ByteString
betweenLinesPS returns the B.ByteString between the two lines given, or Nothing if they do not appear.
break_after_nth_newline :: Int -> ByteString -> Maybe (ByteString, ByteString)
break_before_nth_newline :: Int -> ByteString -> (ByteString, ByteString)
Produced by Haddock version 2.4.2