binary-io-0.2.0: Read and write values of types that implement Binary

Safe HaskellNone
LanguageHaskell2010

Data.Binary.IO

Contents

Description

Read and write values of types that implement Binary from and to Handles

Synopsis

Readers

data ReaderError Source #

An error that can occur during reading

Since: 0.0.1

Constructors

ReaderGetError

Error from the Get operation

Fields

data Reader Source #

Since: 0.0.1

Instances
CanGet Reader Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Reader -> Get a -> IO a Source #

newReader Source #

Arguments

:: Handle

Handle that will be read from

-> IO Reader 

Create a new reader.

Reading using the Reader may throw ReaderError.

The internal position of the Reader is not advanced when it throws an exception during reading. This has the consequence that if you're trying to read with the same faulty Get operation multiple times, you will always receive an exception.

Other threads reading from the Handle will interfere with read operations of the Reader. However, the Reader itself is thread-safe and can be utilized concurrently.

Once the Handle reaches EOF, it will be closed.

The given Handle will be swiched to binary mode via hSetBinaryMode.

Since: 0.0.1

newReaderWith Source #

Arguments

:: IO ByteString

Chunk producer

-> IO Reader 

This function works very similar to newReader except no Handle is involved.

Since: 0.1.1

Writers

data Writer Source #

Since: 0.0.1

Instances
CanPut Writer Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Writer -> Put -> IO () Source #

newWriter Source #

Arguments

:: Handle

Handle that will be written to

-> Writer 

Create a writer.

Other threads writing to the same Handle do not interfere with the resulting Writer. The Writer may be used concurrently.

Since: 0.0.1

newWriterWith Source #

Arguments

:: (ByteString -> IO ())

Chunk handler

-> Writer 

Create a writer using a function that handles the output chunks.

Since: 0.1.1

Pipe

newPipe :: IO (Reader, Writer) Source #

Create a connected pair of Reader and Writer.

Since: 0.2.0

Duplex

data Duplex Source #

Pair of Reader and Writer

Since: 0.0.1

Constructors

Duplex 
Instances
CanPut Duplex Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Duplex -> Put -> IO () Source #

CanGet Duplex Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Duplex -> Get a -> IO a Source #

newDuplex Source #

Arguments

:: Handle

Handle that will be read from and written to

-> IO Duplex 

Create a new duplex. The Duplex inherits all the properties of Reader and Writer when created with newReader and newWriter.

Since: 0.0.1

newDuplexWith :: IO ByteString -> (ByteString -> IO ()) -> IO Duplex Source #

Combines newReaderWith and newWriterWith.

Since: 0.1.1

Classes

class CanGet r where Source #

r can execute Get operations

Since: 0.0.1

Methods

runGet Source #

Arguments

:: r

Reader / source

-> Get a

Operation to execute

-> IO a 
Instances
CanGet Duplex Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Duplex -> Get a -> IO a Source #

CanGet Reader Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Reader -> Get a -> IO a Source #

read Source #

Arguments

:: (CanGet r, Binary a) 
=> r

Read source

-> IO a 

Read something from r.

Since: 0.0.1

class CanPut w where Source #

w can execute Put operations

Since: 0.0.1

Methods

runPut Source #

Arguments

:: w

Writer / target

-> Put

Operation to execute

-> IO () 
Instances
CanPut Handle Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Handle -> Put -> IO () Source #

CanPut Duplex Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Duplex -> Put -> IO () Source #

CanPut Writer Source # 
Instance details

Defined in Data.Binary.IO

Methods

runPut :: Writer -> Put -> IO () Source #

write Source #

Arguments

:: (CanPut w, Binary a) 
=> w

Write target

-> a

Value to be written

-> IO () 

Write something to w.

Since: 0.0.1