Knowledge Base, Libraries, Snippets, Unicode File-paths
Posted: 20 Dec 2021 16:38
I had thought of posting this in Maintaining the KnowledgeBase but decided it needed some discussion.
It is related to fhSQL library not compatible with ANSI encoding (20060) and Plugin Warning - Unicode Ahead! (17926) and similar discussions.
Knowledge Base Code Snippets
Some FH v7 fhUtils, fhFileUtils and Plugin API functions make several of the KB Code Snippets redundant, unless coding for FH v5 or FH v6. Also, most KB Code Snippets for File and Folder Management use lfs that does not support Unicode file-paths.
So should those redundant KB Code Snippets simply be deleted?
Alternatively, many could be replaced by functions from fhUtils and fhFileUtils that use File System Objects instead of lfs, but apart from me who will use them?
Another option is to publish fhUtils and fhFileUtils in a form compatible with FH v5 and FH v6.
I have experimented with that and it only needs trivial changes to produce working modules that could be added to the KB Code Snippets &/or included in the Install Library Modules plugin.
Directory Tree Code Snippet
There is nothing in any of the library modules that provide this Directory Tree functionality.
This Code Snippet uses lfs so does not support Unicode file-paths, but I've written a variant using File System Objects to support Unicode paths because I need it.
The attribute table returned is different but mostly better than the lfs version and easily adapted for most purposes.
The biggest change is the file Date-Time stamps are strings such as dd/mm/yyyy hh:mm:ss instead of an integer number of seconds since 1 Jan 1970 that is used by lfs and Lua os.time(), etc.
It is easy to convert the strings to integer form except for a Daylight Saving Time (BST) snag that can give a 1-hour discrepancy.
That Date-Time string to integer conversion can be added as Code Snippet.
Should I simply replace the existing Directory Tree Code Snippet with my new code or keep both versions?
Load/Save Text File
fhFileUtils functions fileGetContents & filePutContents do not support Unicode file-paths and readTextFile has limitations.
The FH v7 API has new fhLoadTextFile and fhSaveTextFile functions that have none of the above issues.
However, fileGetContents does load binary files as well as text files.
Should the FH v7 API functions be mentioned somewhere in the fhFleUtils description?
It is related to fhSQL library not compatible with ANSI encoding (20060) and Plugin Warning - Unicode Ahead! (17926) and similar discussions.
Knowledge Base Code Snippets
Some FH v7 fhUtils, fhFileUtils and Plugin API functions make several of the KB Code Snippets redundant, unless coding for FH v5 or FH v6. Also, most KB Code Snippets for File and Folder Management use lfs that does not support Unicode file-paths.
So should those redundant KB Code Snippets simply be deleted?
Alternatively, many could be replaced by functions from fhUtils and fhFileUtils that use File System Objects instead of lfs, but apart from me who will use them?
Another option is to publish fhUtils and fhFileUtils in a form compatible with FH v5 and FH v6.
I have experimented with that and it only needs trivial changes to produce working modules that could be added to the KB Code Snippets &/or included in the Install Library Modules plugin.
Directory Tree Code Snippet
There is nothing in any of the library modules that provide this Directory Tree functionality.
This Code Snippet uses lfs so does not support Unicode file-paths, but I've written a variant using File System Objects to support Unicode paths because I need it.
The attribute table returned is different but mostly better than the lfs version and easily adapted for most purposes.
The biggest change is the file Date-Time stamps are strings such as dd/mm/yyyy hh:mm:ss instead of an integer number of seconds since 1 Jan 1970 that is used by lfs and Lua os.time(), etc.
It is easy to convert the strings to integer form except for a Daylight Saving Time (BST) snag that can give a 1-hour discrepancy.
That Date-Time string to integer conversion can be added as Code Snippet.
Should I simply replace the existing Directory Tree Code Snippet with my new code or keep both versions?
Load/Save Text File
fhFileUtils functions fileGetContents & filePutContents do not support Unicode file-paths and readTextFile has limitations.
The FH v7 API has new fhLoadTextFile and fhSaveTextFile functions that have none of the above issues.
However, fileGetContents does load binary files as well as text files.
Should the FH v7 API functions be mentioned somewhere in the fhFleUtils description?