HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulebase-4.20.2.0Haskell2010

GHC.IO.BufferedIO

Class of buffered IO devices

  • 1 class
  • 4 values
  • Packagebase-4.20.2.0
  • Exports5
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceBufferedIO.hs
classclass BufferedIO dev where
#

The purpose of BufferedIO is to provide a common interface for I/O devices that can read and write data through a buffer. Devices that implement BufferedIO include ordinary files, memory-mapped files, and bytestrings. The underlying device implementing a System.IO.Handle must provide BufferedIO.

Methods

  • newBuffer :: dev -> BufferState -> IO (Buffer Word8)

    allocate a new buffer. The size of the buffer is at the discretion of the device; e.g. for a memory-mapped file the buffer will probably cover the entire file.

  • fillReadBuffer :: dev -> Buffer Word8 -> IO (Int, Buffer Word8)

    reads bytes into the buffer, blocking if there are no bytes available. Returns the number of bytes read (zero indicates end-of-file), and the new buffer.

  • fillReadBuffer0 :: dev -> Buffer Word8 -> IO (Maybe Int, Buffer Word8)

    reads bytes into the buffer without blocking. Returns the number of bytes read (Nothing indicates end-of-file), and the new buffer.

  • emptyWriteBuffer :: dev -> Buffer Word8 -> IO (Buffer Word8)

    Prepares an empty write buffer. This lets the device decide how to set up a write buffer: the buffer may need to point to a specific location in memory, for example. This is typically used by the client when switching from reading to writing on a buffered read/write device.

    There is no corresponding operation for read buffers, because before reading the client will always call fillReadBuffer.

  • flushWriteBuffer :: dev -> Buffer Word8 -> IO (Buffer Word8)

    Flush all the data from the supplied write buffer out to the device. The returned buffer should be empty, and ready for writing.

  • flushWriteBuffer0 :: dev -> Buffer Word8 -> IO (Int, Buffer Word8)

    Flush data from the supplied write buffer out to the device without blocking. Returns the number of bytes written and the remaining buffer.

Instances1BufferedIO
  • BufferedIO FDDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.FD