binary-io-0.0.1: Read and write values of types that implement Binary from and to Handles

Safe HaskellSafe
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 -> (a -> IO b) -> IO b 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. The same is true for follow-up actions when using readWith.

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

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

Duplex

data Duplex Source #

Pair of Reader and Writer

Since: 0.0.1

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 -> (a -> IO b) -> IO b 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

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

-> (a -> IO b)

What to do with a

-> IO b 
Instances
CanGet Duplex Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Duplex -> Get a -> (a -> IO b) -> IO b Source #

CanGet Reader Source # 
Instance details

Defined in Data.Binary.IO

Methods

runGet :: Reader -> Get a -> (a -> IO b) -> IO b Source #

read Source #

Arguments

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

Read source

-> IO a 

Read something from r.

Since: 0.0.1

readWith Source #

Arguments

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

Read source

-> (a -> IO b)

What to do with a

-> IO b 

Read something from r and perform an IO action with it.

If the given action throws an exception, the read is not considered successful and will not advance the underlying read source.

Keep in mind, long running actions on a will block other threads when they try to read the from the same source 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