Working with files in Uniface? The filedump
statement is your Swiss Army knife for copying data from source objects to files! π§ Whether you're handling text, images, or raw data, this powerful command has got you covered.
This comprehensive guide is based on the official Uniface 10.4 documentation, with AI assistance to help break down complex concepts into digestible insights.
π What is filedump?
The filedump
statement copies the contents of a source object to a specified file. Think of it as your data export tool that handles everything from simple text files to complex Unicode formats and binary data.
π― Basic Syntax
filedump {/text {/nobom} {/append} | /image | /raw | /web } Source, FileName {, UnicodeFormat | CharacterSet}
π Essential Qualifiers
Qualifier | Purpose | Use Case |
---|---|---|
/text |
Default behavior - converts raw data to system charset | π Standard text files |
/nobom |
Omits Unicode Byte-Order-Mark | π§ JSON files, web standards |
/append |
Adds content to existing file | π Log files, data accumulation |
/image |
Handles image data (removes # indicator) | πΌοΈ Image processing |
/raw |
Writes raw UTF-8 data unchanged | β‘ Binary data, exact copies |
/web |
Handles browser-downloaded files | π Web applications |
π οΈ Parameters Deep Dive
Source Parameter
Your data source - can be a string, field, variable, or function result. This is where your content lives! π¦
FileName Parameter
Destination path and filename. Remember these constraints:
- π Maximum 255 bytes total length
- π« Cannot end with directory separator
- π Can include ZIP archives
- π Supports platform-independent separators (
/
,\
,[a.b]
)
Character Encoding Options
π Uniface supports extensive Unicode formats:
- UTF-8, UTF-16, UTF-32 (with BE/LE variants)
- ISO-8859 series (Western, Eastern European, Cyrillic, Arabic, etc.)
- Windows code pages (1250-1256)
- Asian encodings (EUC-JP, GB2312, Big5, KSC_5601)
π¨ Practical Examples
π Simple File Creation
NAME = "Hello, World!"
filedump NAME, "greeting.txt"
π Appending to Files
filedump NAME, "logfile.txt"
filedump/append "%%^", "logfile.txt" ; Add newline
filedump/append "Additional data", "logfile.txt"
π Web File Handling
filedump/web UPLOADNAME.ENTITY.MODEL, "downloads/uploaded_file.pdf"
πΌοΈ Image Processing
filedump/image IMAGEDATA, "output/photo.jpg"
π§ Advanced Unicode Handling
Working with international data? Uniface automatically handles XML encoding attributes! π
XML Encoding Examples
- CP1252 β
<?xml version="1.0" encoding="ISO-8859-1"?>
- SJIS β
<?xml version="1.0" encoding="Shift_JIS"?>
- UTF8 β
<?xml version="1.0" encoding="UTF-8"?>
π‘ Pro Tip: BOM Management
JSON and some web standards don't play nice with BOMs. Use /nobom
to prevent encoding issues:
filedump/nobom JSONDATA, "api_response.json", "UTF-8"
π Return Values and Error Handling
Success Indicators
- β₯ 0: Number of bytes written β
Common Error Codes
- -1: I/O error during write π«
- -4: Cannot open file π
- -12: Read/write error (disk full?) πΎ
- -13: OS command error β οΈ
- -16 to -30: Network errors π
π― Best Practices
1. Always Check Return Values
filedump TEXTFIELD, "/home/user/output.txt"
if $status < 0
message "Error: File operation failed with code %%$status%%"
else
message "Successfully wrote %%$status%% bytes"
endif
2. Handle Character Encoding Explicitly
Don't rely on defaults! Specify your encoding for predictable results:
filedump XMLDATA, "output.xml", "UTF-8"
3. Use Proper Path Separators
Let Uniface handle platform differences with generic separators:
filedump DATA, "reports/monthly/sales.txt" ; Works everywhere!
π Troubleshooting Common Issues
File Locked Errors
Getting -4 errors? Check if another process has the file open! π
Unicode Problems
Garbled characters? Verify your character set matches your data encoding! π€
Large File Handling
Watch for -12 errors with large files - check available disk space! πΎ
π Conclusion
The filedump
statement is incredibly versatile for file operations in Uniface. From simple text exports to complex Unicode handling and web file management, it's an essential tool in your development toolkit! π οΈ
Remember to always handle errors gracefully and specify character encodings explicitly for robust applications. Happy coding! π
Top comments (0)