Skip to content

Language Reference ‐ Streams Library

Andreas AFENTAKIS edited this page Oct 29, 2025 · 2 revisions

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.

Stream Statements

The List of Stream Statements includes the statements:

  1. FILESTREAM
  2. SCOPY
  3. MEMSTREAM
  4. SREWIND
  5. STOS
  6. Planned Stream Statements (SSEEK, SCLOSE)

FILESTREAM

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 IN stream, is only for input, the OUT is only for output. The INMEMORY implementation 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.

SCOPY

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.

MEMSTREAM

Create a new in-memory stream for fast, temporary access.

MEMSTREAM stream_name
  • stream_name: Identifier for the memory stream.

STOS

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.

Syntax

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.

Behavior

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

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 

End

SREWIND

Rewind a stream to the beginning.

SREWIND stream_name
  • stream_name: Identifier of the stream to rewind.

Planned Stream Statements

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.

Stream Functions

slength()

Get the total length of a stream.

slength("stream_name")
  • Returns the total length (in bytes or records) of the specified stream.

sposition()

Get the current read/write position in a stream.

sposition("stream_name")
  • Returns the cursor position inside the stream.

Remarks

  • 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.

Clone this wiki locally