-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Common lower-level functions needed by various streaming data libraries -- @package streaming-commons @version 0.1.13 module Data.Streaming.Zlib.Lowlevel data ZStreamStruct type ZStream' = Ptr ZStreamStruct zstreamNew :: IO ZStream' data Strategy StrategyDefault :: Strategy StrategyFiltered :: Strategy StrategyHuffman :: Strategy StrategyRLE :: Strategy StrategyFixed :: Strategy deflateInit2 :: ZStream' -> Int -> WindowBits -> Int -> Strategy -> IO () inflateInit2 :: ZStream' -> WindowBits -> IO () c_free_z_stream_inflate :: FunPtr (ZStream' -> IO ()) c_free_z_stream_deflate :: FunPtr (ZStream' -> IO ()) c_set_avail_in :: ZStream' -> Ptr CChar -> CUInt -> IO () c_set_avail_out :: ZStream' -> Ptr CChar -> CUInt -> IO () c_get_avail_out :: ZStream' -> IO CUInt c_get_avail_in :: ZStream' -> IO CUInt c_get_next_in :: ZStream' -> IO (Ptr CChar) c_call_inflate_noflush :: ZStream' -> IO CInt c_call_deflate_noflush :: ZStream' -> IO CInt c_call_deflate_finish :: ZStream' -> IO CInt c_call_deflate_flush :: ZStream' -> IO CInt c_call_deflate_full_flush :: ZStream' -> IO CInt c_call_deflate_set_dictionary :: ZStream' -> Ptr CChar -> CUInt -> IO () c_call_inflate_set_dictionary :: ZStream' -> Ptr CChar -> CUInt -> IO () instance Show Strategy instance Eq Strategy instance Ord Strategy instance Enum Strategy -- | This is a middle-level wrapper around the zlib C API. It allows you to -- work fully with bytestrings and not touch the FFI at all, but is still -- low-level enough to allow you to implement high-level abstractions -- such as enumerators. Significantly, it does not use lazy IO. -- -- You'll probably need to reference the docs a bit to understand the -- WindowBits parameters below, but a basic rule of thumb is 15 is for -- zlib compression, and 31 for gzip compression. -- -- A simple streaming compressor in pseudo-code would look like: -- --
--   def <- initDeflate ...
--   popper <- feedDeflate def rawContent
--   pullPopper popper
--   ...
--   finishDeflate def sendCompressedData
--   
-- -- You can see a more complete example is available in the included -- file-test.hs. module Data.Streaming.Zlib -- | The state of an inflation (eg, decompression) process. All allocated -- memory is automatically reclaimed by the garbage collector. Also can -- contain the inflation dictionary that is used for decompression. data Inflate -- | Initialize an inflation process with the given WindowBits. You -- will need to call feedInflate to feed compressed data to this -- and finishInflate to extract the final chunk of decompressed -- data. initInflate :: WindowBits -> IO Inflate -- | Initialize an inflation process with the given WindowBits. -- Unlike initInflate a dictionary for inflation is set which must match -- the one set during compression. initInflateWithDictionary :: WindowBits -> ByteString -> IO Inflate -- | Feed the given ByteString to the inflater. Return a -- Popper, an IO action that returns the decompressed data a chunk -- at a time. The Popper must be called to exhaustion before using -- the Inflate object again. -- -- Note that this function automatically buffers the output to -- defaultChunkSize, and therefore you won't get any data from the -- popper until that much decompressed data is available. After you have -- fed all of the compressed data to this function, you can extract your -- final chunk of decompressed data using finishInflate. feedInflate :: Inflate -> ByteString -> IO Popper -- | As explained in feedInflate, inflation buffers your -- decompressed data. After you call feedInflate with your last -- chunk of compressed data, you will likely have some data still sitting -- in the buffer. This function will return it to you. finishInflate :: Inflate -> IO ByteString -- | Flush the inflation buffer. Useful for interactive application. -- -- This is actually a synonym for finishInflate. It is provided -- for its more semantic name. -- -- Since 0.0.3 flushInflate :: Inflate -> IO ByteString -- | Retrieve any data remaining after inflating. For more information on -- motivation, see: -- -- https://github.com/fpco/streaming-commons/issues/20 -- -- Since 0.1.11 getUnusedInflate :: Inflate -> IO ByteString -- | The state of a deflation (eg, compression) process. All allocated -- memory is automatically reclaimed by the garbage collector. data Deflate -- | Initialize a deflation process with the given compression level and -- WindowBits. You will need to call feedDeflate to feed -- uncompressed data to this and finishDeflate to extract the -- final chunks of compressed data. initDeflate :: Int -> WindowBits -> IO Deflate -- | Initialize an deflation process with the given compression level and -- WindowBits. Unlike initDeflate a dictionary for deflation is -- set. initDeflateWithDictionary :: Int -> ByteString -> WindowBits -> IO Deflate -- | Feed the given ByteString to the deflater. Return a -- Popper, an IO action that returns the compressed data a chunk -- at a time. The Popper must be called to exhaustion before using -- the Deflate object again. -- -- Note that this function automatically buffers the output to -- defaultChunkSize, and therefore you won't get any data from the -- popper until that much compressed data is available. After you have -- fed all of the decompressed data to this function, you can extract -- your final chunks of compressed data using finishDeflate. feedDeflate :: Deflate -> ByteString -> IO Popper -- | As explained in feedDeflate, deflation buffers your compressed -- data. After you call feedDeflate with your last chunk of -- uncompressed data, use this to flush the rest of the data and signal -- end of input. finishDeflate :: Deflate -> Popper -- | Flush the deflation buffer. Useful for interactive application. -- Internally this passes Z_SYNC_FLUSH to the zlib library. -- -- Unlike finishDeflate, flushDeflate does not signal end -- of input, meaning you can feed more uncompressed data afterward. -- -- Since 0.0.3 flushDeflate :: Deflate -> Popper -- | Full flush the deflation buffer. Useful for interactive applications -- where previously streamed data may not be available. Using -- fullFlushDeflate too often can seriously degrade compression. -- Internally this passes Z_FULL_FLUSH to the zlib library. -- -- Like flushDeflate, fullFlushDeflate does not signal end -- of input, meaning you can feed more uncompressed data afterward. -- -- Since 0.1.5 fullFlushDeflate :: Deflate -> Popper -- | This specifies the size of the compression window. Larger values of -- this parameter result in better compression at the expense of higher -- memory usage. -- -- The compression window size is the value of the the window bits raised -- to the power 2. The window bits must be in the range 8..15 -- which corresponds to compression window sizes of 256b to 32Kb. The -- default is 15 which is also the maximum size. -- -- The total amount of memory used depends on the window bits and the -- MemoryLevel. See the MemoryLevel for the details. data WindowBits :: * WindowBits :: Int -> WindowBits -- | The default WindowBits is 15 which is also the maximum size. defaultWindowBits :: WindowBits -- | Exception that can be thrown from the FFI code. The parameter is the -- numerical error code from the zlib library. Quoting the zlib.h file -- directly: -- -- data ZlibException ZlibException :: Int -> ZlibException -- | An IO action that returns the next chunk of data, returning -- Nothing when there is no more data to be popped. type Popper = IO PopperRes data PopperRes PRDone :: PopperRes PRNext :: !ByteString -> PopperRes PRError :: !ZlibException -> PopperRes instance Typeable ZlibException instance Typeable PopperRes instance Show ZlibException instance Show PopperRes instance Exception ZlibException module Data.Streaming.Process.Internal -- | Wraps up the standard ProcessHandle to avoid the -- waitForProcess deadlock. See the linked documentation from -- the module header for more information. -- -- Since 0.1.4 data StreamingProcessHandle StreamingProcessHandle :: ProcessHandle -> (TMVar ExitCode) -> StreamingProcessHandle -- | Class for all things which can be used to provide standard input. -- -- Since 0.1.4 class InputSource a isStdStream :: InputSource a => (Maybe Handle -> IO a, Maybe StdStream) -- | Class for all things which can be used to consume standard output or -- error. -- -- Since 0.1.4 class OutputSink a osStdStream :: OutputSink a => (Maybe Handle -> IO a, Maybe StdStream) instance OutputSink Handle instance InputSource Handle -- | A full tutorial for this module is available on FP School of Haskell: -- https://www.fpcomplete.com/user/snoyberg/library-documentation/data-conduit-process. -- -- Note that, while the tutorial covers Data.Streaming.Process, -- this module is the basis of the streaming version, and almost all -- concepts there apply here. module Data.Streaming.Process -- | The primary function for running a process. Note that, with the -- exception of UseProvidedHandle, the values for std_in, -- std_out and std_err will be ignored by this -- function. -- -- Since 0.1.4 streamingProcess :: (MonadIO m, InputSource stdin, OutputSink stdout, OutputSink stderr) => CreateProcess -> m (stdin, stdout, stderr, StreamingProcessHandle) -- | Inherit the stream from the current process. -- -- Since 0.1.4 data Inherited Inherited :: Inherited -- | Close the stream with the child process. -- -- Since 0.1.4 data ClosedStream ClosedStream :: ClosedStream -- | Use the Handle provided by the CreateProcess value. -- This would allow you, for example, to open up a Handle to a -- file, set it as std_out, and avoid any additional overhead of -- dealing with providing that data to your process. -- -- Since 0.1.4 data UseProvidedHandle UseProvidedHandle :: UseProvidedHandle -- | Wraps up the standard ProcessHandle to avoid the -- waitForProcess deadlock. See the linked documentation from -- the module header for more information. -- -- Since 0.1.4 data StreamingProcessHandle -- | Blocking call to wait for a process to exit. -- -- Since 0.1.4 waitForStreamingProcess :: MonadIO m => StreamingProcessHandle -> m ExitCode -- | STM version of waitForStreamingProcess. -- -- Since 0.1.4 waitForStreamingProcessSTM :: StreamingProcessHandle -> STM ExitCode -- | Non-blocking call to check for a process exit code. -- -- Since 0.1.4 getStreamingProcessExitCode :: MonadIO m => StreamingProcessHandle -> m (Maybe ExitCode) -- | STM version of getStreamingProcessExitCode. -- -- Since 0.1.4 getStreamingProcessExitCodeSTM :: StreamingProcessHandle -> STM (Maybe ExitCode) -- | Get the raw ProcessHandle from a -- StreamingProcessHandle. Note that you should avoid using this -- to get the process exit code, and instead use the provided functions. -- -- Since 0.1.4 streamingProcessHandleRaw :: StreamingProcessHandle -> ProcessHandle -- | Get the TMVar storing the process exit code. In general, one -- of the above functions should be used instead to avoid accidentally -- corrupting the variable's state.. -- -- Since 0.1.4 streamingProcessHandleTMVar :: StreamingProcessHandle -> TMVar ExitCode -- | Class for all things which can be used to provide standard input. -- -- Since 0.1.4 class InputSource a -- | Class for all things which can be used to consume standard output or -- error. -- -- Since 0.1.4 class OutputSink a -- | Run a process and supply its streams to the given callback function. -- After the callback completes, wait for the process to complete and -- check its exit code. If the exit code is not a success, throw a -- ProcessExitedUnsuccessfully. -- -- Since 0.1.7 withCheckedProcess :: (InputSource stdin, OutputSink stderr, OutputSink stdout, MonadIO m) => CreateProcess -> (stdin -> stdout -> stderr -> m b) -> m b -- | Indicates that a process exited with an non-success exit code. -- -- Since 0.1.7 data ProcessExitedUnsuccessfully ProcessExitedUnsuccessfully :: CreateProcess -> ExitCode -> ProcessExitedUnsuccessfully instance Typeable ProcessExitedUnsuccessfully instance Exception ProcessExitedUnsuccessfully instance Show ProcessExitedUnsuccessfully instance OutputSink UseProvidedHandle instance OutputSink Inherited instance OutputSink ClosedStream instance InputSource UseProvidedHandle instance InputSource Inherited instance InputSource ClosedStream module Data.Streaming.Network.Internal -- | Settings for a TCP server. It takes a port to listen on, and an -- optional hostname to bind to. data ServerSettings ServerSettings :: !Int -> !HostPreference -> !(Maybe Socket) -> !(Socket -> IO ()) -> !Bool -> !Int -> ServerSettings serverPort :: ServerSettings -> !Int serverHost :: ServerSettings -> !HostPreference -- | listening socket serverSocket :: ServerSettings -> !(Maybe Socket) serverAfterBind :: ServerSettings -> !(Socket -> IO ()) serverNeedLocalAddr :: ServerSettings -> !Bool serverReadBufferSize :: ServerSettings -> !Int -- | Settings for a TCP client, specifying how to connect to the server. data ClientSettings ClientSettings :: !Int -> !ByteString -> !Family -> !Int -> ClientSettings clientPort :: ClientSettings -> !Int clientHost :: ClientSettings -> !ByteString clientAddrFamily :: ClientSettings -> !Family clientReadBufferSize :: ClientSettings -> !Int -- | Which host to bind. -- -- Note: The IsString instance recognizes the following special -- values: -- -- -- -- Any other values is treated as a hostname. As an example, to bind to -- the IPv4 local host only, use "127.0.0.1". data HostPreference HostAny :: HostPreference HostIPv4 :: HostPreference HostIPv4Only :: HostPreference HostIPv6 :: HostPreference HostIPv6Only :: HostPreference Host :: String -> HostPreference -- | Representation of a single UDP message data Message Message :: {-# UNPACK #-} !ByteString -> !SockAddr -> Message msgData :: Message -> {-# UNPACK #-} !ByteString msgSender :: Message -> !SockAddr -- | The data passed to an Application. data AppData AppData :: !(IO ByteString) -> !(ByteString -> IO ()) -> !SockAddr -> !(Maybe SockAddr) -> !(IO ()) -> Maybe Socket -> AppData appRead' :: AppData -> !(IO ByteString) appWrite' :: AppData -> !(ByteString -> IO ()) appSockAddr' :: AppData -> !SockAddr appLocalAddr' :: AppData -> !(Maybe SockAddr) appCloseConnection' :: AppData -> !(IO ()) appRawSocket' :: AppData -> Maybe Socket -- | Settings for a Unix domain sockets server. data ServerSettingsUnix ServerSettingsUnix :: !FilePath -> !(Socket -> IO ()) -> !Int -> ServerSettingsUnix serverPath :: ServerSettingsUnix -> !FilePath serverAfterBindUnix :: ServerSettingsUnix -> !(Socket -> IO ()) serverReadBufferSizeUnix :: ServerSettingsUnix -> !Int -- | Settings for a Unix domain sockets client. data ClientSettingsUnix ClientSettingsUnix :: !FilePath -> !Int -> ClientSettingsUnix clientPath :: ClientSettingsUnix -> !FilePath clientReadBufferSizeUnix :: ClientSettingsUnix -> !Int -- | The data passed to a Unix domain sockets Application. data AppDataUnix AppDataUnix :: !(IO ByteString) -> !(ByteString -> IO ()) -> AppDataUnix appReadUnix :: AppDataUnix -> !(IO ByteString) appWriteUnix :: AppDataUnix -> !(ByteString -> IO ()) instance Eq HostPreference instance Ord HostPreference instance Show HostPreference instance Read HostPreference instance IsString HostPreference module Data.Streaming.Network -- | Settings for a TCP server. It takes a port to listen on, and an -- optional hostname to bind to. data ServerSettings -- | Settings for a TCP client, specifying how to connect to the server. data ClientSettings -- | Which host to bind. -- -- Note: The IsString instance recognizes the following special -- values: -- -- -- -- Any other values is treated as a hostname. As an example, to bind to -- the IPv4 local host only, use "127.0.0.1". data HostPreference -- | Representation of a single UDP message data Message Message :: {-# UNPACK #-} !ByteString -> !SockAddr -> Message msgData :: Message -> {-# UNPACK #-} !ByteString msgSender :: Message -> !SockAddr -- | The data passed to an Application. data AppData -- | Settings for a Unix domain sockets server. data ServerSettingsUnix -- | Settings for a Unix domain sockets client. data ClientSettingsUnix -- | The data passed to a Unix domain sockets Application. data AppDataUnix -- | Smart constructor. serverSettingsTCP :: Int -> HostPreference -> ServerSettings -- | Create a server settings that uses an already available listening -- socket. Any port and host modifications made to this value will be -- ignored. -- -- Since 0.1.1 serverSettingsTCPSocket :: Socket -> ServerSettings -- | Smart constructor. clientSettingsTCP :: Int -> ByteString -> ClientSettings -- | Smart constructor. serverSettingsUDP :: Int -> HostPreference -> ServerSettings -- | Smart constructor. clientSettingsUDP :: Int -> ByteString -> ClientSettings -- | Smart constructor. serverSettingsUnix :: FilePath -> ServerSettingsUnix -- | Smart constructor. clientSettingsUnix :: FilePath -> ClientSettingsUnix message :: ByteString -> SockAddr -> Message class HasPort a portLens :: (HasPort a, Functor f) => (Int -> f Int) -> a -> f a class HasAfterBind a afterBindLens :: (HasAfterBind a, Functor f) => ((Socket -> IO ()) -> f (Socket -> IO ())) -> a -> f a class HasReadWrite a readLens :: (HasReadWrite a, Functor f) => (IO ByteString -> f (IO ByteString)) -> a -> f a writeLens :: (HasReadWrite a, Functor f) => ((ByteString -> IO ()) -> f (ByteString -> IO ())) -> a -> f a class HasPath a pathLens :: (HasPath a, Functor f) => (FilePath -> f FilePath) -> a -> f a setPort :: HasPort a => Int -> a -> a setHost :: ByteString -> ClientSettings -> ClientSettings -- | Set the address family for the given settings. -- -- Since 0.1.3 setAddrFamily :: Family -> ClientSettings -> ClientSettings setAfterBind :: HasAfterBind a => (Socket -> IO ()) -> a -> a setNeedLocalAddr :: Bool -> ServerSettings -> ServerSettings setReadBufferSize :: HasReadBufferSize a => Int -> a -> a setPath :: HasPath a => FilePath -> a -> a getPort :: HasPort a => a -> Int getHost :: ClientSettings -> ByteString -- | Get the address family for the given settings. -- -- Since 0.1.3 getAddrFamily :: ClientSettings -> Family getAfterBind :: HasAfterBind a => a -> (Socket -> IO ()) getNeedLocalAddr :: ServerSettings -> Bool getReadBufferSize :: HasReadBufferSize a => a -> Int getPath :: HasPath a => a -> FilePath appRead :: HasReadWrite a => a -> IO ByteString appWrite :: HasReadWrite a => a -> ByteString -> IO () appSockAddr :: AppData -> SockAddr appLocalAddr :: AppData -> Maybe SockAddr -- | Close the underlying connection. One possible use case is simulating -- connection failures in a test suite. -- -- Since 0.1.6 appCloseConnection :: AppData -> IO () -- | Get the raw socket for this AppData, if available. -- -- Since 0.1.12 appRawSocket :: AppData -> Maybe Socket -- | Attempt to bind a listening Socket on the given host/port -- using given SocketType. If no host is given, will use the -- first address available. bindPortGen :: SocketType -> Int -> HostPreference -> IO Socket -- | Bind to a random port number. Especially useful for writing network -- tests. -- -- This will attempt 30 different port numbers before giving up and -- throwing an exception. -- -- Since 0.1.1 bindRandomPortGen :: SocketType -> HostPreference -> IO (Int, Socket) -- | Attempt to connect to the given host/port using given -- SocketType. getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo) -- | Attempt to connect to the given hostportaddress family using -- given SocketType. -- -- Since 0.1.3 getSocketFamilyGen :: SocketType -> String -> Int -> Family -> IO (Socket, AddrInfo) -- | Try to accept a connection, recovering automatically from exceptions. -- -- As reported by Kazu against Warp, "resource exhausted (Too many open -- files)" may be thrown by accept(). This function will catch that -- exception, wait a second, and then try again. acceptSafe :: Socket -> IO (Socket, SockAddr) unassignedPorts :: UArray Int Int -- | Get a port from the IANA list of unassigned ports. -- -- Internally, this function uses an IORef to cycle through the -- list of ports getUnassignedPort :: IO Int -- | Attempt to bind a listening Socket on the given host/port. If -- no host is given, will use the first address available. -- maxListenQueue is topically 128 which is too short for high -- performance servers. So, we specify 'max 2048 maxListenQueue' to the -- listen queue. bindPortTCP :: Int -> HostPreference -> IO Socket -- | Bind a random TCP port. -- -- See bindRandomPortGen. -- -- Since 0.1.1 bindRandomPortTCP :: HostPreference -> IO (Int, Socket) -- | Attempt to connect to the given host/port. getSocketTCP :: ByteString -> Int -> IO (Socket, SockAddr) -- | Attempt to connect to the given hostportaddress family. -- -- Since 0.1.3 getSocketFamilyTCP :: ByteString -> Int -> Family -> IO (Socket, SockAddr) safeRecv :: Socket -> Int -> IO ByteString -- | Run an Application with the given settings. This function -- will create a new listening socket, accept connections on it, and -- spawn a new thread for each connection. runTCPServer :: ServerSettings -> (AppData -> IO ()) -> IO a -- | Run an Application by connecting to the specified server. runTCPClient :: ClientSettings -> (AppData -> IO a) -> IO a type ConnectionHandle = Socket -> SockAddr -> Maybe SockAddr -> IO () runTCPServerWithHandle :: ServerSettings -> ConnectionHandle -> IO a -- | Attempt to bind a listening Socket on the given host/port. If -- no host is given, will use the first address available. bindPortUDP :: Int -> HostPreference -> IO Socket -- | Bind a random UDP port. -- -- See bindRandomPortGen -- -- Since 0.1.1 bindRandomPortUDP :: HostPreference -> IO (Int, Socket) -- | Attempt to connect to the given host/port. getSocketUDP :: String -> Int -> IO (Socket, AddrInfo) -- | Attempt to bind a listening Unix domain socket at the given path. bindPath :: FilePath -> IO Socket -- | Attempt to connect to the given Unix domain socket path. getSocketUnix :: FilePath -> IO Socket -- | Run an Application with the given settings. This function -- will create a new listening socket, accept connections on it, and -- spawn a new thread for each connection. runUnixServer :: ServerSettingsUnix -> (AppDataUnix -> IO ()) -> IO a -- | Run an Application by connecting to the specified server. runUnixClient :: ClientSettingsUnix -> (AppDataUnix -> IO a) -> IO a instance HasReadWrite AppDataUnix instance HasReadWrite AppData instance HasReadBufferSize ServerSettingsUnix instance HasReadBufferSize ClientSettings instance HasReadBufferSize ServerSettings instance HasAfterBind ServerSettingsUnix instance HasAfterBind ServerSettings instance HasPath ClientSettingsUnix instance HasPath ServerSettingsUnix instance HasPort ClientSettings instance HasPort ServerSettings -- | Streaming functions for interacting with the filesystem. module Data.Streaming.Filesystem data DirStream :: * -- | openDirStream dir calls opendir to obtain a -- directory stream for dir. openDirStream :: FilePath -> IO DirStream readDirStream :: DirStream -> IO (Maybe FilePath) -- | closeDirStream dp calls closedir to close the -- directory stream dp. closeDirStream :: DirStream -> IO () data FileType FTFile :: FileType -- | symlink to file FTFileSym :: FileType FTDirectory :: FileType -- | symlink to a directory FTDirectorySym :: FileType FTOther :: FileType getFileType :: FilePath -> IO FileType instance Typeable FileType instance Show FileType instance Read FileType instance Eq FileType instance Ord FileType -- | The standard openFile call on Windows causing problematic -- file locking in some cases. This module provides a cross-platform file -- reading API without the file locking problems on Windows. -- -- This module always opens files in binary mode. -- -- readChunk will return an empty ByteString on EOF. module Data.Streaming.FileRead data ReadHandle openFile :: FilePath -> IO ReadHandle closeFile :: ReadHandle -> IO () readChunk :: ReadHandle -> IO ByteString -- | Buffers for Builders. This is a partial copy of -- blaze-builder-0.3.3.4's -- Blaze.ByteString.Builder.Internal.Buffer module, which was -- removed in blaze-builder-0.4. -- -- If you are using blaze-builder 0.3.*, this module just re-exports from -- Blaze.ByteString.Builder.Internal.Buffer. -- -- Since 0.1.10.0 module Data.Streaming.ByteString.Builder.Buffer -- | A buffer Buffer fpbuf p0 op ope describes a buffer with the -- underlying byte array fpbuf..ope, the currently written slice -- p0..op and the free space op..ope. -- -- Since 0.1.10.0 data Buffer Buffer :: {-# UNPACK #-} !(ForeignPtr Word8) -> {-# UNPACK #-} !(Ptr Word8) -> {-# UNPACK #-} !(Ptr Word8) -> {-# UNPACK #-} !(Ptr Word8) -> Buffer -- | The size of the free space of the buffer. -- -- Since 0.1.10.0 freeSize :: Buffer -> Int -- | The size of the written slice in the buffer. -- -- Since 0.1.10.0 sliceSize :: Buffer -> Int -- | The size of the whole byte array underlying the buffer. -- -- Since 0.1.10.0 bufferSize :: Buffer -> Int -- | allocBuffer size allocates a new buffer of size -- size. -- -- Since 0.1.10.0 allocBuffer :: Int -> IO Buffer -- | Resets the beginning of the next slice and the next free byte such -- that the whole buffer can be filled again. -- -- Since 0.1.10.0 reuseBuffer :: Buffer -> Buffer -- | Move the beginning of the slice to the next free byte such that the -- remaining free space of the buffer can be filled further. This -- operation is safe and can be used to fill the remaining part of the -- buffer after a direct insertion of a bytestring or a flush. -- -- Since 0.1.10.0 nextSlice :: Int -> Buffer -> Maybe Buffer -- | Update the end of slice pointer. -- -- Since 0.1.10.0 updateEndOfSlice :: Buffer -> Ptr Word8 -> Buffer -- | Convert the buffer to a bytestring. This operation is unsafe in the -- sense that created bytestring shares the underlying byte array with -- the buffer. Hence, depending on the later use of this buffer (e.g., if -- it gets reset and filled again) referential transparency may be lost. -- -- Since 0.1.10.0 unsafeFreezeBuffer :: Buffer -> ByteString -- | Convert a buffer to a non-empty bytestring. See -- unsafeFreezeBuffer for the explanation of why this operation -- may be unsafe. -- -- Since 0.1.10.0 unsafeFreezeNonEmptyBuffer :: Buffer -> Maybe ByteString -- | A buffer allocation strategy (buf0, nextBuf) specifies the -- initial buffer to use and how to compute a new buffer nextBuf -- minSize buf with at least size minSize from a filled -- buffer buf. The double nesting of the IO monad helps -- to ensure that the reference to the filled buffer buf is lost -- as soon as possible, but the new buffer doesn't have to be allocated -- too early. -- -- Since 0.1.10.0 type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer)) -- | The simplest buffer allocation strategy: whenever a buffer is -- requested, allocate a new one that is big enough for the next build -- step to execute. -- -- NOTE that this allocation strategy may spill quite some memory upon -- direct insertion of a bytestring by the builder. Thats no problem for -- garbage collection, but it may lead to unreasonably high memory -- consumption in special circumstances. -- -- Since 0.1.10.0 allNewBuffersStrategy :: Int -> BufferAllocStrategy -- | An unsafe, but possibly more efficient buffer allocation strategy: -- reuse the buffer, if it is big enough for the next build step to -- execute. -- -- Since 0.1.10.0 reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy defaultStrategy :: BufferAllocStrategy -- | Convert a stream of bytestring Builders into a stream of -- ByteStrings. -- -- Adapted from blaze-builder-enumerator, written by Michael Snoyman and -- Simon Meier. -- -- Note that the functions here can work in any monad built on top of -- IO or ST. -- -- Also provides toByteStringIO* like -- Blaze.ByteString.Builders, for Data.ByteString.Builder. -- -- Since 0.1.9 module Data.Streaming.ByteString.Builder type BuilderRecv = Builder -> IO BuilderPopper -- | Provides a series of ByteStrings until empty, at which point -- it provides an empty ByteString. -- -- Since 0.1.10.0 type BuilderPopper = IO ByteString type BuilderFinish = IO (Maybe ByteString) newByteStringBuilderRecv :: BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish) -- | Run the builder with a defaultChunkSized buffer and execute the -- given IO action whenever the buffer is full or gets flushed. -- --
--   toByteStringIO = toByteStringIOWith defaultChunkSize
--   
-- -- Since 0.1.9 toByteStringIO :: (ByteString -> IO ()) -> Builder -> IO () -- | toByteStringIOWith bufSize io b runs the builder b -- with a buffer of at least the size bufSize and executes the -- IO action io whenever the buffer is full. -- -- Compared to toLazyByteStringWith this function requires less -- allocation, as the output buffer is only allocated once at the start -- of the serialization and whenever something bigger than the current -- buffer size has to be copied into the buffer, which should happen very -- seldomly for the default buffer size of 32kb. Hence, the pressure on -- the garbage collector is reduced, which can be an advantage when -- building long sequences of bytes. -- -- Since 0.1.9 toByteStringIOWith :: Int -> (ByteString -> IO ()) -> Builder -> IO () -- | Use a pre-existing buffer to toByteStringIOWith. -- -- Since 0.1.9 toByteStringIOWithBuffer :: Int -> (ByteString -> IO ()) -> Builder -> ForeignPtr Word8 -> IO () -- | A buffer Buffer fpbuf p0 op ope describes a buffer with the -- underlying byte array fpbuf..ope, the currently written slice -- p0..op and the free space op..ope. -- -- Since 0.1.10.0 data Buffer -- | The size of the free space of the buffer. -- -- Since 0.1.10.0 freeSize :: Buffer -> Int -- | The size of the written slice in the buffer. -- -- Since 0.1.10.0 sliceSize :: Buffer -> Int -- | The size of the whole byte array underlying the buffer. -- -- Since 0.1.10.0 bufferSize :: Buffer -> Int -- | allocBuffer size allocates a new buffer of size -- size. -- -- Since 0.1.10.0 allocBuffer :: Int -> IO Buffer -- | Resets the beginning of the next slice and the next free byte such -- that the whole buffer can be filled again. -- -- Since 0.1.10.0 reuseBuffer :: Buffer -> Buffer -- | Move the beginning of the slice to the next free byte such that the -- remaining free space of the buffer can be filled further. This -- operation is safe and can be used to fill the remaining part of the -- buffer after a direct insertion of a bytestring or a flush. -- -- Since 0.1.10.0 nextSlice :: Int -> Buffer -> Maybe Buffer -- | Convert the buffer to a bytestring. This operation is unsafe in the -- sense that created bytestring shares the underlying byte array with -- the buffer. Hence, depending on the later use of this buffer (e.g., if -- it gets reset and filled again) referential transparency may be lost. -- -- Since 0.1.10.0 unsafeFreezeBuffer :: Buffer -> ByteString -- | Convert a buffer to a non-empty bytestring. See -- unsafeFreezeBuffer for the explanation of why this operation -- may be unsafe. -- -- Since 0.1.10.0 unsafeFreezeNonEmptyBuffer :: Buffer -> Maybe ByteString -- | A buffer allocation strategy (buf0, nextBuf) specifies the -- initial buffer to use and how to compute a new buffer nextBuf -- minSize buf with at least size minSize from a filled -- buffer buf. The double nesting of the IO monad helps -- to ensure that the reference to the filled buffer buf is lost -- as soon as possible, but the new buffer doesn't have to be allocated -- too early. -- -- Since 0.1.10.0 type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer)) -- | The simplest buffer allocation strategy: whenever a buffer is -- requested, allocate a new one that is big enough for the next build -- step to execute. -- -- NOTE that this allocation strategy may spill quite some memory upon -- direct insertion of a bytestring by the builder. Thats no problem for -- garbage collection, but it may lead to unreasonably high memory -- consumption in special circumstances. -- -- Since 0.1.10.0 allNewBuffersStrategy :: Int -> BufferAllocStrategy -- | An unsafe, but possibly more efficient buffer allocation strategy: -- reuse the buffer, if it is big enough for the next build step to -- execute. -- -- Since 0.1.10.0 reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy defaultStrategy :: BufferAllocStrategy -- | Typeclass to stream blaze-builder and bytestring(-builder) -- Builders. -- -- Since 0.1.10.0 module Data.Streaming.ByteString.Builder.Class -- | Typeclass to stream blaze-builder (< 0.4) and bytestring(-builder) -- Builders. This is primarily to aid the transition from -- blaze-builder to bytestring Builders (if using blaze-builder -- >= 0.4, there is only one instance, since the Builder type -- is shared). -- -- Since 0.1.10.0 class Monoid b => StreamingBuilder b newBuilderRecv :: StreamingBuilder b => BufferAllocStrategy -> IO (b -> IO BuilderPopper, BuilderFinish) builderFlush :: StreamingBuilder b => b instance StreamingBuilder Builder -- | Convert a stream of blaze-builder Builders into a stream of -- ByteStrings. -- -- Adapted from blaze-builder-enumerator, written by myself and Simon -- Meier. -- -- Note: if you have blaze-builder >= 0.4, newBlazeRecv just -- calls newByteStringBuilderRecv module Data.Streaming.Blaze type BlazeRecv = Builder -> IO BlazePopper -- | Provides a series of ByteStrings until empty, at which point -- it provides an empty ByteString. -- -- Since 0.1.2 type BlazePopper = IO ByteString type BlazeFinish = IO (Maybe ByteString) newBlazeRecv :: BufferAllocStrategy -> IO (BlazeRecv, BlazeFinish) -- | A buffer Buffer fpbuf p0 op ope describes a buffer with the -- underlying byte array fpbuf..ope, the currently written slice -- p0..op and the free space op..ope. -- -- Since 0.1.10.0 data Buffer -- | The size of the free space of the buffer. -- -- Since 0.1.10.0 freeSize :: Buffer -> Int -- | The size of the written slice in the buffer. -- -- Since 0.1.10.0 sliceSize :: Buffer -> Int -- | The size of the whole byte array underlying the buffer. -- -- Since 0.1.10.0 bufferSize :: Buffer -> Int -- | allocBuffer size allocates a new buffer of size -- size. -- -- Since 0.1.10.0 allocBuffer :: Int -> IO Buffer -- | Resets the beginning of the next slice and the next free byte such -- that the whole buffer can be filled again. -- -- Since 0.1.10.0 reuseBuffer :: Buffer -> Buffer -- | Move the beginning of the slice to the next free byte such that the -- remaining free space of the buffer can be filled further. This -- operation is safe and can be used to fill the remaining part of the -- buffer after a direct insertion of a bytestring or a flush. -- -- Since 0.1.10.0 nextSlice :: Int -> Buffer -> Maybe Buffer -- | Convert the buffer to a bytestring. This operation is unsafe in the -- sense that created bytestring shares the underlying byte array with -- the buffer. Hence, depending on the later use of this buffer (e.g., if -- it gets reset and filled again) referential transparency may be lost. -- -- Since 0.1.10.0 unsafeFreezeBuffer :: Buffer -> ByteString -- | Convert a buffer to a non-empty bytestring. See -- unsafeFreezeBuffer for the explanation of why this operation -- may be unsafe. -- -- Since 0.1.10.0 unsafeFreezeNonEmptyBuffer :: Buffer -> Maybe ByteString -- | A buffer allocation strategy (buf0, nextBuf) specifies the -- initial buffer to use and how to compute a new buffer nextBuf -- minSize buf with at least size minSize from a filled -- buffer buf. The double nesting of the IO monad helps -- to ensure that the reference to the filled buffer buf is lost -- as soon as possible, but the new buffer doesn't have to be allocated -- too early. -- -- Since 0.1.10.0 type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer)) -- | The simplest buffer allocation strategy: whenever a buffer is -- requested, allocate a new one that is big enough for the next build -- step to execute. -- -- NOTE that this allocation strategy may spill quite some memory upon -- direct insertion of a bytestring by the builder. Thats no problem for -- garbage collection, but it may lead to unreasonably high memory -- consumption in special circumstances. -- -- Since 0.1.10.0 allNewBuffersStrategy :: Int -> BufferAllocStrategy -- | An unsafe, but possibly more efficient buffer allocation strategy: -- reuse the buffer, if it is big enough for the next build step to -- execute. -- -- Since 0.1.10.0 reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy defaultStrategy :: BufferAllocStrategy -- | Provides a stream-based approach to decoding Unicode data. Each -- function below works the same way: you give it a chunk of data, and it -- gives back a DecodeResult. If the parse was a success, then -- you get a chunk of Text (possibly empty) and a continuation -- parsing function. If the parse was a failure, you get a chunk of -- successfully decoded Text (possibly empty) and the unconsumed -- bytes. -- -- In order to indicate end of stream, you pass an empty -- ByteString to the decode function. This call may result in a -- failure, if there were unused bytes left over from a previous step -- which formed part of a code sequence. module Data.Streaming.Text -- | O(n) Convert a ByteString into a 'Stream Char', using -- UTF-8 encoding. decodeUtf8 :: ByteString -> DecodeResult -- | O(n) Convert a ByteString into a 'Stream Char', using -- UTF-8 encoding. decodeUtf8Pure :: ByteString -> DecodeResult -- | O(n) Convert a ByteString into a 'Stream Char', using -- little endian UTF-16 encoding. decodeUtf16LE :: ByteString -> DecodeResult -- | O(n) Convert a ByteString into a 'Stream Char', using -- big endian UTF-16 encoding. decodeUtf16BE :: ByteString -> DecodeResult -- | O(n) Convert a ByteString into a 'Stream Char', using -- little endian UTF-32 encoding. decodeUtf32LE :: ByteString -> DecodeResult -- | O(n) Convert a ByteString into a 'Stream Char', using -- big endian UTF-32 encoding. decodeUtf32BE :: ByteString -> DecodeResult data DecodeResult DecodeResultSuccess :: !Text -> !(ByteString -> DecodeResult) -> DecodeResult DecodeResultFailure :: !Text -> !ByteString -> DecodeResult instance Show S instance Eq CodePoint instance Show CodePoint instance Num CodePoint instance Storable CodePoint instance Eq DecoderState instance Show DecoderState instance Num DecoderState instance Storable DecoderState