Copyright | (c) Don Stewart 2006-2008 (c) Duncan Coutts 2006-2011 |
---|---|
License | BSD-style |
Maintainer | dons00@gmail.com, duncan@community.haskell.org |
Stability | unstable |
Portability | non-portable |
Safe Haskell | Unsafe |
Language | Haskell2010 |
A module containing semi-public ByteString
internals. This exposes
the ByteString
representation and low level construction functions.
Modules which extend the ByteString
system will need to use this module
while ideally most users will be able to make do with the public interface
modules.
Synopsis
- data ByteString
- type LazyByteString = ByteString
- chunk :: ByteString -> ByteString -> ByteString
- foldrChunks :: (ByteString -> a -> a) -> a -> ByteString -> a
- foldlChunks :: (a -> ByteString -> a) -> a -> ByteString -> a
- invariant :: ByteString -> Bool
- checkInvariant :: ByteString -> ByteString
- defaultChunkSize :: Int
- smallChunkSize :: Int
- chunkOverhead :: Int
- packBytes :: [Word8] -> ByteString
- packChars :: [Char] -> ByteString
- unpackBytes :: ByteString -> [Word8]
- unpackChars :: ByteString -> [Char]
- fromStrict :: ByteString -> ByteString
- toStrict :: ByteString -> ByteString
The lazy ByteString
type and representation
data ByteString Source #
A space-efficient representation of a Word8
vector, supporting many
efficient operations.
A lazy ByteString
contains 8-bit bytes, or by using the operations
from Data.ByteString.Lazy.Char8 it can be interpreted as containing
8-bit characters.
Instances
type LazyByteString = ByteString Source #
Type synonym for the lazy flavour of ByteString
.
Since: bytestring-0.11.2.0
chunk :: ByteString -> ByteString -> ByteString Source #
Smart constructor for Chunk
. Guarantees the data type invariant.
foldrChunks :: (ByteString -> a -> a) -> a -> ByteString -> a Source #
Consume the chunks of a lazy ByteString with a natural right fold.
foldlChunks :: (a -> ByteString -> a) -> a -> ByteString -> a Source #
Consume the chunks of a lazy ByteString with a strict, tail-recursive, accumulating left fold.
Data type invariant and abstraction function
invariant :: ByteString -> Bool Source #
The data type invariant:
Every ByteString is either Empty
or consists of non-null
StrictByteString
s. All functions must preserve this.
checkInvariant :: ByteString -> ByteString Source #
Lazily checks that the given ByteString
satisfies the data type's
"no empty chunks" invariant, raising an exception in place of the
first chunk that does not satisfy the invariant.
Chunk allocation sizes
defaultChunkSize :: Int Source #
The chunk size used for I/O. Currently set to 32k, less the memory management overhead
smallChunkSize :: Int Source #
The recommended chunk size. Currently set to 4k, less the memory management overhead
chunkOverhead :: Int Source #
The memory management overhead. Currently this is tuned for GHC only.
Conversion with lists: packing and unpacking
packBytes :: [Word8] -> ByteString Source #
packChars :: [Char] -> ByteString Source #
unpackBytes :: ByteString -> [Word8] Source #
unpackChars :: ByteString -> [Char] Source #
Conversions with strict ByteString
fromStrict :: ByteString -> ByteString Source #
O(1) Convert a strict ByteString
into a lazy ByteString
.
toStrict :: ByteString -> ByteString Source #
O(n) Convert a lazy ByteString
into a strict ByteString
.
Note that this is an expensive operation that forces the whole lazy ByteString into memory and then copies all the data. If possible, try to avoid converting back and forth between strict and lazy bytestrings.