DEV Community

Peter + AI
Peter + AI

Posted on

πŸ—‚οΈ Mastering Uniface filedump: Your Complete Guide to File Operations

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}
Enter fullscreen mode Exit fullscreen mode

πŸš€ 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"
Enter fullscreen mode Exit fullscreen mode

πŸ“ Appending to Files

filedump NAME, "logfile.txt"
filedump/append "%%^", "logfile.txt"  ; Add newline
filedump/append "Additional data", "logfile.txt"
Enter fullscreen mode Exit fullscreen mode

🌐 Web File Handling

filedump/web UPLOADNAME.ENTITY.MODEL, "downloads/uploaded_file.pdf"
Enter fullscreen mode Exit fullscreen mode

πŸ–ΌοΈ Image Processing

filedump/image IMAGEDATA, "output/photo.jpg"
Enter fullscreen mode Exit fullscreen mode

πŸ”§ 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"
Enter fullscreen mode Exit fullscreen mode

πŸ“Š 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
Enter fullscreen mode Exit fullscreen mode

2. Handle Character Encoding Explicitly

Don't rely on defaults! Specify your encoding for predictable results:

filedump XMLDATA, "output.xml", "UTF-8"
Enter fullscreen mode Exit fullscreen mode

3. Use Proper Path Separators

Let Uniface handle platform differences with generic separators:

filedump DATA, "reports/monthly/sales.txt"  ; Works everywhere!
Enter fullscreen mode Exit fullscreen mode

πŸ” 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)