If you need to remove a Unicode or a UTF-8 BOM from a binary BLOB file, you can use the BlobRemoveBOM function.
Removing a Unicode or a UTF-8 BOM from a binary BLOB file using the BlobRemoveBOM function:
-
For the purpose of this example, begin by creating a sample BLOB file containing a BOM. Save it under your <My Documents>\Magic\projects\<current project> folder. Call this file utf8.txt.
-
To create the variables that you will use in this example, open the Flow Variables repository.
-
There, create two BLOB variables called F.utf8 and F.utf8nobom. Then, create a logical variable called F.logic.
-
Drag a Flow Data utility into your flow.
-
To begin the process of removing a BOM, you need to load the sample file into a BLOB using the File2Blb function. In the Flow Data Configuration dialog box, click Add.
-
In the Action column, select Update from the drop-down list.
-
In the Type column, select Flow.
-
In the Name column, select the F.utf8 BLOB variable that you previously created.
-
In the Encoding column, select Binary.
-
In the Update Expression column, click to open the Expression Editor.
-
In the Expression Editor, enter the following expression (as shown in the image below), and then click OK:
File2Blb (EnvVal ('currentprojectdir')&'utf8.txt')
-
The next stage is to remove the BOM contained in the newly-created file. This is done by using the BlobRemoveBOM function. In the Flow Data Configuration dialog box, click Add.
-
In the Action column, select Update from the drop-down list.
-
In the Type column, select Flow.
-
In the Name column, select the F.utf8nobom BLOB variable that you previously created.
-
In the Encoding column, select Binary.
-
In the Update Expression column, click to open the Expression Editor.
-
In the Expression Editor, enter the following expression (as shown in the image below), and then click OK:
BlobRemoveBOM ( F.utf8 )
-
Now you need to load your BLOB, with its BOM removed, into a file. You do this with the Blb2File function. In the Flow Data Configuration dialog box, click Add.
-
In the Action column, select Update from the drop-down list.
-
In the Type column, select Flow.
-
In the Name column, select the F.logic logical variable that you previously created.
-
In the Update Expression column, click to open the Expression Editor.
-
In the Expression Editor, enter the following expression (as shown in the image below), and then click OK:
Blb2File ( F.utf8nobom , EnvVal('currentprojectdir') &'utf8withoutbom.txt')
-
Click OK to close the Flow Data utility.
-
Build your project.
-
Now, when you debug and run your project, you will see a new .txt file in the <My Documents>\Magic\projects\<current project> folder called utf8withoutbom.txt. This file is the original file, now minus its BOM. Its name is taken from the expression that you entered in step 23. You can use a Hex Editor to verify that the BOM has been removed.