stdio-0.1.0.0: A simple and high performance IO toolkit for Haskell

Copyright(c) Dong Han 2017-2018
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Std.IO.Buffered

Contents

Description

This module provide buffered IO interface.

Synopsis

Input & Output device

class Input i where Source #

Input device

Laws: readInput should return 0 on EOF.

Note: readInput is considered not thread-safe, e.g. A Input device can only be used with a single BufferedInput, If multiple BufferedInput s are opened on a same Input device, the behaviour will be undefined.

Methods

readInput :: HasCallStack => i -> Ptr Word8 -> Int -> IO Int Source #

Instances
Input UVStream Source # 
Instance details

Defined in Std.IO.UV.Manager

Methods

readInput :: UVStream -> Ptr Word8 -> Int -> IO Int Source #

Input StdStream Source # 
Instance details

Defined in Std.IO.StdStream

Input UVFileReader Source # 
Instance details

Defined in Std.IO.FileSystemT

Input UVFile Source # 
Instance details

Defined in Std.IO.FileSystemT

Methods

readInput :: UVFile -> Ptr Word8 -> Int -> IO Int Source #

Input UVFileReader Source # 
Instance details

Defined in Std.IO.FileSystem

Input UVFile Source # 
Instance details

Defined in Std.IO.FileSystem

Methods

readInput :: UVFile -> Ptr Word8 -> Int -> IO Int Source #

class Output o where Source #

Output device

Laws: writeOutput should not return until all data are written (may not necessarily flushed to hardware, that should be done in device specific way).

Methods

writeOutput :: HasCallStack => o -> Ptr Word8 -> Int -> IO () Source #

Instances
Output UVStream Source # 
Instance details

Defined in Std.IO.UV.Manager

Methods

writeOutput :: UVStream -> Ptr Word8 -> Int -> IO () Source #

Output StdStream Source # 
Instance details

Defined in Std.IO.StdStream

Methods

writeOutput :: StdStream -> Ptr Word8 -> Int -> IO () Source #

Output UVFileWriter Source # 
Instance details

Defined in Std.IO.FileSystemT

Methods

writeOutput :: UVFileWriter -> Ptr Word8 -> Int -> IO () Source #

Output UVFile Source # 
Instance details

Defined in Std.IO.FileSystemT

Methods

writeOutput :: UVFile -> Ptr Word8 -> Int -> IO () Source #

Output UVFileWriter Source # 
Instance details

Defined in Std.IO.FileSystem

Methods

writeOutput :: UVFileWriter -> Ptr Word8 -> Int -> IO () Source #

Output UVFile Source # 
Instance details

Defined in Std.IO.FileSystem

Methods

writeOutput :: UVFile -> Ptr Word8 -> Int -> IO () Source #

Buffered Input

data BufferedInput i Source #

Input device with buffer, NOT THREAD SAFE!

newBufferedInput Source #

Arguments

:: input 
-> Int

Input buffer size

-> IO (BufferedInput input) 

readBuffer :: (HasCallStack, Input i) => BufferedInput i -> IO Bytes Source #

Request bytes from BufferedInput.

The buffering logic is quite simple:

If we have pushed back bytes, directly return it, otherwise we read using buffer size. If we read N bytes, and N is larger than half of the buffer size, then we freeze buffer and return, otherwise we copy buffer into result and reuse buffer afterward.

unReadBuffer :: (HasCallStack, Input i) => Bytes -> BufferedInput i -> IO () Source #

Push bytes back into buffer

readParser :: (HasCallStack, Input i) => Parser a -> BufferedInput i -> IO (ReadResult a) Source #

Read buffer and parse with Parser.

readExactly :: (HasCallStack, Input i) => Int -> BufferedInput i -> IO Bytes Source #

Read exactly N bytes

If EOF reached before N bytes read, a ShortReadException will be thrown

readToMagic :: (HasCallStack, Input i) => Word8 -> BufferedInput i -> IO Bytes Source #

Read until reach a magic bytes

If EOF is reached before meet a magic byte, partial bytes are returned.

readToMagic' :: (HasCallStack, Input i) => Word8 -> BufferedInput i -> IO Bytes Source #

Read until reach a magic bytes

If EOF is reached before meet a magic byte, a ShortReadException will be thrown.

readLine :: (HasCallStack, Input i) => BufferedInput i -> IO Bytes Source #

Read to a linefeed ('\n' or '\r\n'), return Bytes before it.

If EOF is reached before meet a magic byte, partial line is returned.

readLine' :: (HasCallStack, Input i) => BufferedInput i -> IO Bytes Source #

Read to a linefeed ('\n' or '\r\n'), return Bytes before it.

If EOF reached before meet a magic byte, a ShortReadException will be thrown.

Buffered Output

data BufferedOutput o Source #

Output device with buffer, NOT THREAD SAFE!

newBufferedOutput Source #

Arguments

:: output 
-> Int

Output buffer size

-> IO (BufferedOutput output) 

writeBuffer :: Output o => BufferedOutput o -> Bytes -> IO () Source #

Write Bytes into buffered handle.

Copy Bytes to buffer if it can hold, otherwise write both buffer(if not empty) and Bytes.

writeBuilder :: Output o => BufferedOutput o -> Builder a -> IO () Source #

Write Bytes into buffered handle.

Copy Bytes to buffer if it can hold, otherwise write both buffer(if not empty) and Bytes.

flushBuffer :: Output f => BufferedOutput f -> IO () Source #

Flush the buffer(if not empty).

Exceptions