Idea

Serge A avatar image
8 Likes"
Serge A suggested

Proper File System API

Flexscript handling of file input-output is not sufficiently flexible nor reliable by modern day standards.

  1. fileopen() allows to open only one file at a time.
  2. There is no way to handle exceptions related to file state or operations. FlexSim models, which rely on Flexscript for input-output, cannot detect nor recover from IO errors.
  3. There are probably caching issues / data leak between consecutive uses of fileopen() [This issue was reported to dev@ on November 28, 2017, but it still persists in FlexSim 2018].
  4. There is no way to ensure that data was written to disk (no flush/sync).
  5. There is no API for binary IO (seeking, reading/writing a fixed number of bytes, etc.).
  6. Text IO facilities do not cover all use cases. filereadline() offers a line-oriented plain-text reading, but there is no character based text reading function/method and no way to get the entire contents of file as is. For writing, fpt() doesn't allow to choose text encoding and line endings.
  7. The facilities to get file metadata and status are very limited. There is fileisreadonly(), but there is no way to get file modification time or size. There is endoffile() predicate, but no way to check badbit/failbit.
  8. FlexSim cannot delete or rename files.
  9. FlexSim cannot create, rename or delete directories, nor change current directory.

The only current workaround is to use C++ modules for all file input-output operations, but it's a complicated solution, which requires a very specific setup, development practices, and results in models which cannot run on out of the box FlexSim installation.

Proposal:

As part of transition of Flexscript to object-oriented API, implement a new file API, with the following features:

  • reading from and writing to multiple files (create File objects?)
  • a full set of seeking, reading and writing commands, both for binary, and for text modes
  • safe open/close, some sort of context manager which ensures that all files are properly closed
  • a mechanism to detect and handle IO errors
  • tools to manage files and directory structure
  • access to file metadata
  • flush/sync method

Given, that Flexscript already mimics some ECMAscript APIs, replicating node.js File System API would be a great solution, but replicating a file API of any other mature language is probably going to be good enough.

Related proposal:

Proper Exception Handling in FlexScript

flexscriptfile handling
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

No Comments

·

Write a Comment

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.