Name
DefineVirtualFileFromString -- define a virtual file from a string source (V5.0)
Synopsis
virtfile$ = DefineVirtualFileFromString(data$, name$[, writable])
Function
This function allows you to define a virtual file from a string source. A virtual file is a file that exists only in memory but you can still pass it to all Hollywood functions and they will act as if the file was really present on a physical drive. DefineVirtualFileFromString() takes two mandatory arguments: In the first argument you have to provide the data that shall constitute your virtual file's contents. Argument two specifies the name of the virtual file. The only thing that is important here is the file extension because it gives Hollywood a hint of the virtual file's type. Thus, you should make sure that you pass the correct file extension. The name does not matter, but the file extension should be passed because not all files can be easily identified by looking at their header bytes.

Starting with Hollywood version 6.1 DefineVirtualFileFromString() also supports the creation of virtual files that can be written to. If you want the virtual file to be writable, you have to set the writable parameter to True. In that case, DefineVirtualFileFromString() will create a writable virtual file for you. The writable file will be initialized with the contents passed in data$. If you pass an empty string in data$, an empty new writable virtual file will be created.

DefineVirtualFileFromString() returns a string describing the virtual file. You can pass this string to all Hollywood functions which accept a file name.

Please note that the file's contents are not limited to text only. You can also pass binary data inside data$ because Hollywood strings can contain special control characters and the NULL character as well. Thus, it is perfectly possible to create virtual files containing binary data with this function.

When you are finished dealing with the virtual file, you should free the virtual file by calling the UndefineVirtualStringFile() function. Doing this is important because it will free any memory occupied by the virtual file.

Inputs
data$
source string that constitutes the virtual file's contents
name$
the name and file extension of the virtual file (see above)
writable
optional: True if this virtual file should be writable, False otherwise (defaults to False) (V6.1)
Results
virtfile$
string describing the virtual file
Example
vf$ = DefineVirtualFileFromString("This is a virtual file test.",
                                  "test.txt")
OpenFile(1, vf$)
While Not Eof(1) Do Print(Chr(ReadChr(1)))
CloseFile(1)
UndefineVirtualStringFile(vf$)
The code above creates a virtual text file and then reads from this virtual file using the Hollywood DOS library.


data$ = DownloadFile("http://www.airsoftsoftwair.de/images/" ..
                     "products/hollywood/47_shot1.jpg")
vf$ = DefineVirtualFileFromString(data$, "image.jpg")
LoadBrush(1, vf$)
DisplayBrush(1, 0, 0)
UndefineVirtualStringFile(vf$)
data$ = Nil
The code above downloads a JPEG image to a string and loads the image directly into Hollywood without having to save it to an external file first.


vf$ = DefineVirtualFileFromString("", "test.txt", True)
OpenFile(1, vf$, #MODE_WRITE)
WriteLine(1, "A virtual file test!")
CloseFile(1)
CopyFile(vf$, GetSystemInfo().UserHome)
UndefineVirtualStringFile(vf$)
The code above writes a string to a virtual file and then copies this virtual file to the user's home directory.

Show TOC