use root/file::write as fullWrite use std/flow::emit use std/flow::trigger use std/text/convert/string::toUtf8 /** Write one file. The bytes received through `data` are written in the file located at `path`. The writing behavior is set up by the parameters: - `append`: bytes are added to the file instead of replacing the existing file; - `create`: if the file does not exists, it is created; - `new`: the file is required to being new, if a file already exists at that path then the writing fails. The amount of written bytes is sent through `amount`. There is no guarantee about its increment, as an undefined number of bytes may be written at once. `finished` is emitted when successful writting is finished. `failure` is emitted if an error occurs, and `error` contains the related text of error(s). */ treatment write(path: string, append: bool = false, create: bool = true, new: bool = false) input data: Stream output finished: Block output failure: Block output error: Stream output amount: Stream { triggerData: trigger() emitFilename: emit(value=path) fullWrite(append=append, create=create, new=new) Self.data -> triggerData.stream,start -> emitFilename.trigger,emit -> fullWrite.path Self.data ----------------------------------------------------------> fullWrite.data fullWrite.finished -> Self.finished fullWrite.failure --> Self.failure fullWrite.error ----> Self.error fullWrite.amount ---> Self.amount } /** Write text in one file. The text received through `text` is written as UTF-8 in the file located at `path`. The writing behavior is set up by the parameters: - `append`: bytes are added to the file instead of replacing the existing file; - `create`: if the file does not exists, it is created; - `new`: the file is required to being new, if a file already exists at that path then the writing fails. The amount of written bytes is sent through `amount`. There is no guarantee about its increment, as an undefined number of bytes may be written at once. `finished` is emitted when successful writting is finished. `failure` is emitted if an error occurs, and `error` contains the related text of error(s). */ treatment writeText(path: string, append: bool = false, create: bool = true, new: bool = false) input text: Stream output finished: Block output failure: Block output error: Stream output amount: Stream { write(path=path, append=append, create=create, new=new) toUtf8() Self.text -> toUtf8.text,encoded -> write.data write.finished -> Self.finished write.failure --> Self.failure write.error ----> Self.error write.amount ---> Self.amount }