-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Memory-backed handles
--   
--   Create memory-backed <a>Handle</a>s, referencing virtual files. This
--   is mostly useful for testing <a>Handle</a>-based APIs without having
--   to interact with the filesystem.
--   
--   <pre>
--   import Data.ByteString (pack)
--   import Data.Knob
--   import System.IO
--   
--   main = do
--       knob &lt;- newKnob (pack [])
--       h &lt;- newFileHandle knob "test.txt" WriteMode
--       hPutStrLn h "Hello world!"
--       hClose h
--       bytes &lt;- Data.Knob.getContents knob
--       putStrLn ("Wrote bytes: " ++ show bytes)
--   </pre>
@package knob
@version 0.2.2


-- | Create memory-backed <a>Handle</a>s, referencing virtual files. This
--   is mostly useful for testing <a>Handle</a>-based APIs without having
--   to interact with the filesystem.
--   
--   <pre>
--   import Data.ByteString (pack)
--   import Data.Knob
--   import System.IO
--   
--   main = do
--       knob &lt;- newKnob (pack [])
--       h &lt;- newFileHandle knob "test.txt" WriteMode
--       hPutStrLn h "Hello world!"
--       hClose h
--       bytes &lt;- Data.Knob.getContents knob
--       putStrLn ("Wrote bytes: " ++ show bytes)
--   </pre>
module Data.Knob

-- | A knob is a basic virtual file, which contains a byte buffer. A knob
--   can have multiple <a>Handle</a>s open to it, each of which behaves
--   like a standard file handle.
--   
--   Use <a>getContents</a> and <a>setContents</a> to inspect and modify
--   the knob's byte buffer.
data Knob
newKnob :: MonadIO m => ByteString -> m Knob
getContents :: MonadIO m => Knob -> m ByteString
setContents :: MonadIO m => Knob -> ByteString -> m ()

-- | Create a new <a>Handle</a> pointing to a <a>Knob</a>. This handle
--   behaves like a file-backed handle for most purposes.
newFileHandle :: MonadIO m => Knob -> String -> IOMode -> m Handle

-- | See <a>newFileHandle</a>.
withFileHandle :: MonadIO m => Knob -> String -> IOMode -> (Handle -> IO a) -> m a

-- | An IO device backed by a <a>Knob</a>. You shouldn't usually use this
--   type directly; use <a>newFileHandle</a> or <a>withFileHandle</a>
--   instead.
data Device
newDevice :: MonadIO m => Knob -> IOMode -> m Device
instance GHC.Internal.IO.BufferedIO.BufferedIO Data.Knob.Device
instance GHC.Internal.IO.Device.IODevice Data.Knob.Device
instance GHC.Internal.IO.Device.RawIO Data.Knob.Device
