buster-2.51: Almost but not quite entirely unlike FRP

App.Behaviours.FileOps

Description

This module handles read, write, encode, and decode of files. It also cleanly handles exceptions by introducing Exception events that are handlable by the behaviours in App.Behaviours.Exception which exit your program gracefully, or by your own user defined exception handlers.

It can handle datatypes EData a with Binary, Show, and Read instances as well.

Synopsis

Documentation

readFileBehaviour :: Read a => String -> EData a -> Behaviour [EData a]Source

readFileBehaviour name datatype looks for any event with the name name and reads the file into an event following the pattern:

  • name: same as filename.
  • group: same as name of the behaviour, name
  • source: "ReadSource"
  • timespan: Persistent
  • eventdata: the file, read in and processed using read to be of the datatype that corresponds to the constructor in the datatype parameter.

NOTE: This function can only be used with EData a where a has a Read instance. For event data without a read instance, use readFileBehaviourNR

readFileBehaviourNR :: String -> EData a -> Behaviour [EData a]Source

readFileBehaviourNR name datatype looks for any event with the name name and reads the file into an event following the pattern:

  • name: same as filename.
  • group: same as name of the behaviour, name
  • source: "ReadSource"
  • timespan: Persistent
  • eventdata: the file, read in and processed using read to be of the datatype that corresponds to the constructor in the datatype parameter. The constructor itself should not be serialized.

NOTE: Attempting to read datatype EOther a using this will cause the program to emit an event with "Exception" as the group and name as the source.

decodeFileBehaviour :: Binary a => String -> EData a -> Behaviour [EData a]Source

decodeFileBehaviour name datatype looks for any event with the name name and reads the file into an event following the pattern:

  • name: same as filename.
  • group: same as name of the behaviour, name
  • source: "ReadSource"
  • timespan: Persistent
  • eventdata: the file, read in and processed using decodeFile to be of the datatype that corresponds to the constructor in the datatype parameter. The constructor itself need not be serialized.

NOTE: This function can only be used with EData a where a has a Binary instance. For event data without a read instance, use decodeFileBehaviourNB

decodeFileBehaviourNB :: String -> EData a -> Behaviour [EData a]Source

readFileBehaviour name datatype looks for any event with the name name and reads the file into an event following the pattern:

  • name: same as filename.
  • group: same as name of the behaviour, name
  • source: "ReadSource"
  • timespan: Persistent
  • eventdata: the file, read in and processed using read to be of the datatype that corresponds to the constructor in the datatype parameter.

NOTE: Attempting to read datatype EOther a using this will cause the program to raise an Event with "Exception" as the group.

writeFileBehaviourNS :: Behaviour [EData a]Source

writeFileBehaviour looks for "WriteFile" named events with event data corresponding to [EString filepath, data constructor contents] and removes them from the bus, writing the file named filepath. Any error is placed on the bus with an Exception event with "WriteFile" as the source.

writeFileBehaviour :: Show a => Behaviour [EData a]Source

writeFileBehaviour looks for "WriteFile" named events with event data corresponding to [EString filepath, data constructor contents] and removes them from the bus, writing the file named filepath. Any error is placed on the bus with an Exception event with "WriteFile" as the source.

NOTE: Attempting to encode 'EOther a' using this will raise an Exception.

encodeFileBehaviourNB :: Behaviour [EData a]Source

writeFileBehaviour looks for "WriteFile" named events with event data corresponding to [EString filepath, data constructor contents] and removes them from the bus, writing the file named filepath. Any error is placed on the bus with an Exception event with "WriteFile" as the source.

NOTE: Attempting to encode 'EOther a' using this will raise an Exception.

encodeFileBehaviour :: Binary a => Behaviour [EData a]Source

writeFileBehaviour looks for "WriteFile" named events with event data corresponding to [EString filepath, data constructor contents] and removes them from the bus, writing the file named filepath. Any error is placed on the bus with an Exception event with "WriteFile" as the source.

NOTE: This can only be used with an EData a where a has a Binary instance.