vfs.writer

function

Library: File system utilities (OMVFS)
Import : omvfs.xmd

Returns: An OmniMark output object to the opened file.


Declaration
export external string sink function writer
        of      value file file-ref

Argument definitions

file-ref
The vfs.file object associated with the file to be written to.


Purpose

You can use vfs.writer to attach an OmniMark stream to a file so that you can send output to that file. In the following program, vfs.open is used to open the file notes.txt. Then vfs.writer is used to attach the open file to an OmniMark stream for writing:

  import "omvfs.xmd" prefixed by vfs.
  
  process
    local vfs.file output-file
    set output-file to vfs.open "/temp/notes.txt"
       for vfs.read-write-mode
    using output as vfs.writer of output-file
       submit #main-input
       ;data is written by find rules

If your program is running in an environment where other programs may be accessing the file you are writing to, it is advisable to lock the file while writing:

  import "omvfs.xmd" prefixed by vfs.
  
  process
    local vfs.file output-file
    set output-file to vfs.open "/temp/Notes.txt"
       for vfs.read-write-mode
    vfs.lock output-file
    using output as vfs.writer of output-file
       submit #main-input
       ;data is written by find rules
    vfs.unlock output-file

Exceptions

The following exceptions may occur: