Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
System.IO
[go: Go Back, main page]

 ParentContentsIndex
System.IO
Contents
Buffers
Files
MappedFiles
Pipes
Arrays as streams
Sockets
Streams
Description
The naming is all subject to change, we're interested in functionality first.
Synopsis
data Buffer
withBuffer :: Buffer -> (Ptr Word8 -> IO a) -> IO a
data ImmutableBuffer
data File
data FileInputStream
data FileOutputStream
type FileOffset = Integer
openFile :: FilePath -> IOMode -> IO File
closeFile :: File -> IO ()
fileSize :: File -> IO Integer
fileSetSize :: File -> Integer -> IO ()
fileRead :: File -> FileOffset -> Integer -> Buffer -> IO ()
fileGet :: File -> FileOffset -> Integer -> IO ImmutableBuffer
fileWrite :: File -> FileOffset -> Integer -> Buffer -> IO ()
fileInputStream :: File -> FileOffset -> IO FileInputStream
fileOutputStream :: File -> FileOffset -> IO FileOutputStream
mapFile :: File -> FileOffset -> Integer -> MapMode -> IO MappedFile
data MappedFile
data PipeInputStream
data PipeOutputStream
createPipe :: IO (PipeInputStream, PipeOutputStream)
data ArrayInputStream
data ArrayOutputStream
iarrayInputStream :: (Ix i, IArray a Word8) => a i Word8 -> i -> ArrayInputStream
marrayInputStream :: (Ix i, MArray a Word8 IO) => a i Word8 -> i -> ArrayInputStream
marrayOutputStream :: (Ix i, MArray a Word8 IO) => a i Word8 -> i -> ArrayOutputStream
data Socket
data SocketInputStream
data SocketOutputStream
socketGetInputStream :: Socket -> SocketInputStream
socketGetOutputStream :: Socket -> SocketOutputStream
class Stream s where
closeStream :: s -> IO ()
isEOS :: s -> IO Bool
setBufferMode :: s -> BufferMode -> IO Bool
getBufferMode :: s -> IO BufferMode
flush :: s -> IO ()
sync :: s -> IO Bool
class InputStream s where
streamGet :: s -> IO Word8
streamReadBuffer :: s -> Integer -> Buffer -> IO ()
streamGetBuffer :: s -> Integer -> IO ImmutableBuffer
streamGetContents :: s -> IO [Word8]
streamGetAvailable :: s -> IO [Word8]
class OutputStream s where
streamPut :: s -> Word8 -> IO ()
streamPuts :: s -> [Word8] -> IO ()
streamWriteBuffer :: s -> Integer -> Buffer -> IO ()
streamPutBuffer :: s -> Integer -> ImmutableBuffer -> IO ()
Buffers
data Buffer
A mutable array of bytes that can be passed to foreign functions.
Instances
MArray Buffer Word8 IO
withBuffer :: Buffer -> (Ptr Word8 -> IO a) -> IO a
data ImmutableBuffer
An immutable array of bytes
Instances
IArray ImmutableBuffer Word8

The idea is that Buffer should be useful for text encoding/decoding.

Implementation notes: on GHC, Buffer could be implemented by IOUArray, using a pinned ByteArray# as the underlying object, so that the buffer address can be passed to foreign functions.

(a StorableArray would do for Buffer, but an IOUArray will be more efficient).

Files
data File
data FileInputStream
Instances
Stream FileInputStream
InputStream FileInputStream
data FileOutputStream
Instances
Stream FileOutputStream
OutputStream FileOutputStream
type FileOffset = Integer
openFile :: FilePath -> IOMode -> IO File
closeFile :: File -> IO ()
fileSize :: File -> IO Integer
fileSetSize :: File -> Integer -> IO ()
fileRead :: File -> FileOffset -> Integer -> Buffer -> IO ()
fileGet :: File -> FileOffset -> Integer -> IO ImmutableBuffer
fileWrite :: File -> FileOffset -> Integer -> Buffer -> IO ()
fileInputStream :: File -> FileOffset -> IO FileInputStream
fileOutputStream :: File -> FileOffset -> IO FileOutputStream
mapFile :: File -> FileOffset -> Integer -> MapMode -> IO MappedFile
MappedFiles
data MappedFile
A portion of a File mapped directly into memory. The data can be read and written using the array operations, and streams to the data can be created using marrayInputStream and marrayOutputStream.
Instances
MArray MappedFile Word8 IO
A MappedFile might be implemented as a StorableArray, with a ForeignPtr inside it. The finalizer can unmap the file.
Pipes
data PipeInputStream
Instances
Stream PipeInputStream
InputStream PipeInputStream
data PipeOutputStream
Instances
Stream PipeOutputStream
OutputStream PipeOutputStream
createPipe :: IO (PipeInputStream, PipeOutputStream)
Arrays as streams
data ArrayInputStream
An input stream created from an array.
Instances
Stream ArrayInputStream
InputStream ArrayInputStream
data ArrayOutputStream
An output stream created from an array.
Instances
Stream ArrayOutputStream
OutputStream ArrayOutputStream
iarrayInputStream :: (Ix i, IArray a Word8) => a i Word8 -> i -> ArrayInputStream
Creates an ArrayInputStream from an immutable array
marrayInputStream :: (Ix i, MArray a Word8 IO) => a i Word8 -> i -> ArrayInputStream
Creates an ArrayInputStream from a mutable array
marrayOutputStream :: (Ix i, MArray a Word8 IO) => a i Word8 -> i -> ArrayOutputStream
Creates an ArrayOutputStream from a mutable array
Sockets
The socket support won't live in System.IO, it will be in Network.Socket as before.
data Socket
data SocketInputStream
Instances
Stream SocketInputStream
InputStream SocketInputStream
data SocketOutputStream
Instances
Stream SocketOutputStream
OutputStream SocketOutputStream
socketGetInputStream :: Socket -> SocketInputStream
socketGetOutputStream :: Socket -> SocketOutputStream

Input and output streams for a socket can be closed independently.

Each socket has only one pair of input/output streams, hence these functions are pure.

Streams
class Stream s where
Methods
closeStream :: s -> IO ()
isEOS :: s -> IO Bool
Note: objections have been raised about this method, and are still to be resolved. It doesn't make as much sense for output streams as it does for input streams.
setBufferMode :: s -> BufferMode -> IO Bool
Sets the buffering mode on the stream. Returns True if the buffereing mode was set, or False if it wasn't. If the stream does not support buffereing, it may return False here.
getBufferMode :: s -> IO BufferMode
Returns the current buffering mode for a stream. On a stream that does not support buffering, the result will always be NoBuffering.
flush :: s -> IO ()
Flushes the buffer to the operating system for an output buffer, or discards buffered data for an input buffer.
sync :: s -> IO Bool
Flushes the buffered data as far as possible, even to the physical media if it can. It returns True if the data has definitely been flushed as far as it can go: to the disk for a disk file, to the screen for a terminal, and so on.
Instances
Stream FileInputStream
Stream FileOutputStream
Stream PipeInputStream
Stream PipeOutputStream
Stream ArrayInputStream
Stream ArrayOutputStream
Stream SocketInputStream
Stream SocketOutputStream
class InputStream s where
Methods
streamGet :: s -> IO Word8
streamReadBuffer :: s -> Integer -> Buffer -> IO ()
streamGetBuffer :: s -> Integer -> IO ImmutableBuffer
streamGetContents :: s -> IO [Word8]
streamGetAvailable :: s -> IO [Word8]
Gets any data which can be read without blocking.
Instances
InputStream FileInputStream
InputStream PipeInputStream
InputStream ArrayInputStream
InputStream SocketInputStream
class OutputStream s where
Methods
streamPut :: s -> Word8 -> IO ()
streamPuts :: s -> [Word8] -> IO ()
streamWriteBuffer :: s -> Integer -> Buffer -> IO ()
streamPutBuffer :: s -> Integer -> ImmutableBuffer -> IO ()
Instances
OutputStream FileOutputStream
OutputStream PipeOutputStream
OutputStream ArrayOutputStream
OutputStream SocketOutputStream
Produced by Haddock version 0.4