DuAEF.DuBinary

Tools to include and extract binary files directly in your script files, allowing to deploy only one .jsx files containing any needed image, preset or executable. You can easily convert binaries to text (*.jsxinc) files using the tools provided with DuAEF. You can then include those *.jsxinc files inside your scripts, and use the toFile() method to extract and use them at runtime.

Example

//First, include the text representation of the file (Add a # before the include word)
include icon.png.jsxinc
// Now, a variable called `icon` (the original file name without extension) is available, you can pass this object to the `DuBinary.toFile()` method to extract it and get an ExtendScript File object representation of it.
// Note: This object is an instance of a `DuBinaryFile` class, which contains all information and a string representation of the original binary file
var iconFile = DuBinary.toFile(icon);
iconFile.fsName; // C:\users\duduf\appData\Roaming\DuAEF\icon.png (Example on Windows)
//You can also directly use a PNG string in ScriptUI without extracting the file. (Add a # before the include word)
var button = somePanel.add('iconbutton',undefined,icon.binAsString);

Methods

static convertToBinaryFile(jsFile, outputFileNameopt) → {File}

Converts a JS file to a binary file
Parameters:
Name Type Attributes Default Description
jsFile File The JS file to convert
outputFileName string <optional>
DuAEF.DuJS.Fs.duaefData/category/binaryfilename The output filename.
Returns:
File - The binary file created, or null if failed
To Do:
  • Do not use $.eval() but parse the file.
Example
//If you don't want to include the file in the script. (Add a # before the include word)
var stringFile = new File("C:\test\image.jpg.jsxinc");
var jpgFile = DuBinary.convertToBinaryFile(stringFile);
// Warning, this method uses `$.eval()` which is a bad security issue.
//This will be changed in the future, but for now, do not use this method for anything else than debugging and testing.

static convertToIncludeFile(binaryFile, categoryopt, outputFileNameopt, varNameopt) → {File}

Converts a binary file to a jsxinc file
Parameters:
Name Type Attributes Default Description
binaryFile File The binary file to convert
category string <optional>
A Category for the file, will be used as a subfolder to extract files. Can have subcategories like "category/subcategory". Default: ""
outputFileName string <optional>
Same folder, same name with .json extension The file name for the output.
varName string <optional>
File name without extension The name of the variable used to store the javascript object.
Returns:
File - The json file created

static parseFilePaths(filePath) → {Array.<string>|int}

Extract paths from a given file. Paths are not checked, be sure to check them before using them. (checking if they exist) Ignore lines starting with "#include". Also returns the surounding elements "path" or 'path'.
Parameters:
Name Type Description
filePath String The path to the file
Returns:
  • Array.<string> - List of paths.
  • int - 1 if the file can't be opened

static toFile(duBinaryFile, outputFileNameopt) → {File|null}

Creates a file from a DuBinaryFile object representation.
Parameters:
Name Type Attributes Default Description
duBinaryFile DuBinaryFile The DuBinaryFile object containing the string representation.
This object will be replaced by the File object created.
If a file object is provided (the file has already been extracted), does nothing.
outputFileName string <optional>
DuAEF.DuJS.Fs.duaefData/DuAEF/category/binaryfilename The output filename.
Returns:
File | null - The file created, null if the file could not be written.
If the file is not written, check user permissions, and check if the file and network access preference is checked
You can check DuAEF.DuAE.App.hasFilesAndNetworkAccess and call DuAEF.DuAE.App.askFilesAndNetworkAccess.
Examples
//First, include the text representation of the file (Add a # before the include word)
include executable.exe.jsxinc
// Now, a variable called `executable` (the original file name without extension) is available, you can pass this object to the `DuBinary.toFile()` method to extract it and get an ExtendScript File object representation of it.
// Note: This object is an instance of a `DuBinaryFile` class, which contains all information and a string representation of the original binary file
var execFile = DuBinary.toFile(executable);
//Now, the file exists in the file system, and execFile is an ExtendScript File object.
// The `DuBinary.toFile()` method extracts the file to the Application Data folder by default.
execFile.fsName; // C:\users\duduf\appData\Roaming\DuAEF\icon.png (Example on Windows)
//You can specify the output file name. (Add a # before the include word)
include preset.ffx.jsxinc
var presetFile = DuBinary.toFile(preset,"C:/test/test_preset.ffx");
presetFile.fsName; // C:\test\test_preset.exe");

static toObj(file, categoryopt) → {DuBinaryFile}

Creates a DuBinaryFile object from a binary file
Parameters:
Name Type Attributes Description
file File The File to convert
category string <optional>
A Category for the file, will be used as a subfolder to extract files. Can have subcategories like "category/subcategory".
Returns:
DuBinaryFile - The DuBinaryFile object containing the file as a string