|Platform||FileMaker 18||MBS Plugin|
|FileMaker Cloud for AWS||✔︎||✔︎|
|FileMaker iOS SDK||✔︎||✔︎|
|Older FileMaker versions||-||✔︎|
|Use in Scripts||✔︎||✔︎|
|Use in Calculations||-||✔︎|
|Use in Custom Functions||-||✔︎|
High level read and write functions
But before you look into the BinaryFile functions, maybe let us point to some high level functions. To just write some text to a file, you can use Text.WriteTextFile function. If you need to append text, you can use Text.AppendTextFile function. For both you can specify text encoding and if needed, you can change line endings with Text.ReplaceNewline function.
To write something to a file, you can use Files.WriteFile, which works for containers and text. And this function can do hex/base64 decoding of the data to write. To write just a container value, you can use Container.WriteFile function.
For reading you can use Container.ReadFile, Files.ReadFile, Files.ReadJPEG, Files.ReadPDF, Files.ReadPNG or Text.ReadTextFile. Depending on what you need to read, you can pick a specialized function or a more generic one.
Close Data File
Closes the data file by passing in a reference number. Our BinaryFile.Close functions works similar.
Create Data File
This script step creates a file. You would do the same with BinaryFile.Create, but the plugin leaves the file open and if you don't want to use it, you can use BinaryFile.Close to close it right away.
Deletes the file as our Files.Delete function does. The MBS function can remove directories, too.
Get Data File Position
Same as BinaryFile.Position function to query position in the file.
Get File Exists
Checks if a file exists on disk.
In MBS Plugin, we have Files.FileExists to check for files, Files.DirectoryExists to check for directory and Files.ItemExists to check for both.
Get File Size
The Files.FileSize function takes a path to check the file size. But BinaryFile.Length checks length of an open file.
Open Data File
In MBS Plugin the BinaryFile.Open function opens the file based on the file path.
Use BinaryFile.Append function to append to an existing file or BinaryFile.Create to create a new one, possibly overwriting an existing file.
Read from Data File
In MBS Plugin the BinaryFile.ReadText function reads text. You specify how many bytes to read and what text encoding to use. You can use BinaryFile.ReadHex to read binary data and return them as hex encoded text. BinaryFile.ReadByte reads a single byte while BinaryFile.ReadInt reads an integer value in 8, 16, 32 or 64 bits of size. BinaryFile.ReadContainer can read some container value, e.g. an image.
Our Files.RenameFile function renames a file. If you need to move it somewhere else, please use Files.MoveFile function. And if the target is the trash, please use Files.MoveToTrash function.
Set Data File Position
The BinaryFile.Seek function changes the position in the current file. You can call BinaryFile.Position to get the new position.
Write to Data File
To write data, you usually use BinaryFile.WriteText function to write text in a given encoding. With BinaryFile.WriteContainer you can write an image, PDF or some other file data into the current file. If your data is hex encoded, the BinaryFile.WriteHex function can decode and write it. You can write single byte value with BinaryFile.WriteByte function, integer numbers from 8 to 64 bit with BinaryFile.WriteInt and floating point numbers with BinaryFile.WriteFloat function.
As you see, the MBS Plugin does the same or more and gives you more flexibility. Have fun!