Home > Language Reference > Classes

StreamFileDB Class

  + Object
    + Stream
      + StreamFileDB

Description

The StreamFileDB class allows you to handle files stored in stream databases. Its implementation relies on the File Streaming API provided by the Palm OS® platform. This class is instantiable, but is neither derivable, nor cloneable.

Stream databases essentially behave as files. You can read or write data, move the file pointer, or execute any operation you are used to execute on desktop computer files. However, underlying implementation stands on Palm OS® databases. Thus, stream databases also have a type, a creator, and other usual Palm OS® database attributes.

Stream databases are typically used for storing and handling data that are not suited to records and databases, such as text files or JPEG images. Unlike memory files managed by the StreamMemory class, a stream database is persistent, and can contain more than 64 KB.

Technically, the data written in a stream database are divided into 4096 bytes blocks, each being stored in a record, jointly with some management information. Maximal number of records being 65534, as for any other database, maximal size of a file stored in a stream database is about 256 MB.

The system differentiates stream databases from other bases by the fact that their AttrStream property is set to True. Only stream databases can be opened and handled by the StreamFileDB class. Any attempt to open a standard database with this class causes a runtime error.

In order to handle a file, you must open it by calling the Open method. If no error occurs, you can then handle the file like any other stream, using the Read, Write and other methods of the Stream object. You can also call methods specific to this type of stream, which are listed at the bottom of this page.

When you are not using a file anymore, it is advisable to close it by calling the Close method. This operation is essential, as for performance reasons, the data written in a StreamFileDB are not immediately stored into memory, but are put into buffers. These are emptied only at file closing, when moving the file pointer, or when an explicit call to the Flush method is performed.

The following example shows how to read content of a text file, and display it in a Field control:

Private Sub Button1_Click()
  Dim f as New StreamFileDB
  Dim s as String

  f.Open "MyTextFile",hbModeOpenExisting+hbModeReadOnly
  f.Read s, f.Size
  f.Close

  Field1.Text=s
End Sub

In order to remove a file, removing merely the database that contains it is sufficient. This can be achieved easily by using the DatabaseInfo class, as shown below:

Private Sub Button2_Click()
  Dim di as New DatabaseInfo

  If di.FindByName("MyTextFile") Then di.Delete
End Sub

You can also use the Info property to retrieve a reference to a properly initialized DatabaseInfo object. However, the file must be open for this property to work.

Note: it is possible to pack any file of your desktop computer inside a Palm OS® database by using the StreamDB Converter utility provided with HB++. Please refer to the documentation of this tool for more information.

Members

MembersDescription
Close Closes the file.
EOF End of file indicator.
FileHand Returns the file handle.
Flush Flushes cached data to storage.
Info Returns a DatabaseInfo object.
Open Creates and/or opens a file.
Truncate Truncates the file from the current pointer position.
Inherited from StreamDescription
Position Stream pointer position.
Read Reads data from a stream.
Seek Moves the stream pointer.
SeekToBegin Moves the pointer to the beginning of the stream.
SeekToEnd Moves the pointer to the end of the stream.
Size Total size of the data in a stream.
Write Writes data to a stream.
Inherited from ObjectDescription
ClassID Returns the type identifier corresponding to the actual class of the object.
Implements Determines whether the object implements the features of a given class.
Iterate Event raised to iterate over the elements of a container object.
Recipient Recipient of events sent by the object.
Serialize Event raised to serialize the object content into a stream.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A