-
Notifications
You must be signed in to change notification settings - Fork 0
Language Reference ‐ Streams Library
The Streams Library in FAST.FBasic offers robust support for file and memory stream operations, enabling advanced IO workflows and data manipulation within programs.
The List of Stream Statements includes the statements:
- FILESTREAM
- SCOPY
- MEMSTREAM
- SREWIND
- STOS
-
Planned Stream Statements (
SSEEK,SCLOSE)
Declare a file-based or in-memory stream and assign it a name.
FILESTREAM stream_name, in|inmemory|out, library, path, file_name- stream_name: Unique identifier for the stream.
- in | inmemory | out: Specify input stream, in-memory stream, or output stream.
- library: (Optional) External library used for stream handling.
- path, file_name: Location and name of the file (for file streams).The
- The
INstream, is only for input, theOUTis only for output. TheINMEMORYimplementation initally opens the file as input stream and then copy it to a MemoryStream. Memory Streams are suitable of opearations that will modify the content.
| Important |
|---|
References to File System operations is a subject of the implementation of the IFBasicFileManagementLayer interface. It is not part of the FBasic interpreter. Library, Path, File are concepts where are handled by the File Managment Layer. The default layer, if no other specified, is using a Root Path that the .NET application should provide and then the Path if the path to file after the Root Path and the Fileis the file name, with the extension. The library is not used. |
Copy the contents of one stream into another.
SCOPY source_stream, destination_stream- source_stream: The stream to copy data from.
- destination_stream: The stream to copy data into.
Create a new in-memory stream for fast, temporary access.
MEMSTREAM stream_name- stream_name: Identifier for the memory stream.
Transfer data between a stream and a string variable. STOS stands for String To Stream or Stream To String, with the direction determined by the specifier FROM or TO.
STOS stream_name FROM string_variable
STOS stream_name TO string_variable
- stream_name: The unique identifier for the stream.
- string_variable: The string variable that provides or receives the stream content.
| Specifier | Direction | Action | Stream Status |
|---|---|---|---|
| FROM | String to Stream | The text content of string_variable is written to stream_name. |
If the stream is already defined as an output or in-memory stream, it is used. If it is not defined, it is automatically created as a new in-memory stream (MEMSTREAM). |
| TO | Stream to String | The entire text content of stream_name is read and stored into string_variable. |
The stream must be already defined before this statement is executed. |
Example demonstrating the STOS statement (Stream TO|FROM String):
REM Stream Example-1
FILESTREAM lorem, in, "", "other", "LoremIpsum.txt" ' Streams Library
FILESTREAM dest, out, "", "Output", "StreamExample1.txt"
stos lorem to text
print "Text length is: "+len(text)
let text=ucase(text)
print mid(text,1,11)
stos dest from text
EndRewind a stream to the beginning.
SREWIND stream_name- stream_name: Identifier of the stream to rewind.
These statements are planned for future versions:
-
SSEEK stream_name, position: Seek to a specific position inside the stream. -
SCLOSE stream_name: Close the stream and release associated resources.
Get the total length of a stream.
slength("stream_name")- Returns the total length (in bytes or records) of the specified stream.
Get the current read/write position in a stream.
sposition("stream_name")- Returns the cursor position inside the stream.
- Stream operations are essential for modular programs that perform extensive data reading and writing tasks.
- FILESTREAM and MEMSTREAM statements let programs switch between persistent and high-speed temporary storage as needed.
- Planned statements SSEEK and SCLOSE will enhance random access and resource management, respectively.