{"id":26214810,"url":"https://github.com/charlierobin/safer-saving-of-files","last_synced_at":"2026-02-03T18:02:11.133Z","repository":{"id":276512000,"uuid":"929496657","full_name":"charlierobin/safer-saving-of-files","owner":"charlierobin","description":"A small utility module (mainly) for helping with safer saving of text and JSON files","archived":false,"fork":false,"pushed_at":"2025-02-08T17:49:32.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T18:30:31.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Xojo","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charlierobin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-08T17:24:38.000Z","updated_at":"2025-02-08T17:49:36.000Z","dependencies_parsed_at":"2025-02-08T18:41:14.945Z","dependency_job_id":null,"html_url":"https://github.com/charlierobin/safer-saving-of-files","commit_stats":null,"previous_names":["charlierobin/safer-saving-of-files"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fsafer-saving-of-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fsafer-saving-of-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fsafer-saving-of-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fsafer-saving-of-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlierobin","download_url":"https://codeload.github.com/charlierobin/safer-saving-of-files/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196623,"owners_count":20251861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-12T10:18:36.085Z","updated_at":"2026-02-03T18:02:06.096Z","avatar_url":"https://github.com/charlierobin.png","language":"Xojo","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A simple Xojo module to facilitate the safer saving of files\n\nIn general: rather than immediately overwriting an old file with a new one of the same name, we write the new file to a temp file, and only then remove the old one and rename the new one to “replace” the old one.\n\nGiven how much more reliable file i/o has become, this is possibly ridiculous overkill, but on the other hand: you just never know, do you?\n\nThe core of the module consists of six methods: three for simple straightforward saving (with no safeguards) of text (.txt), JSON (.json) and XML (.xml), and three which “wrap” the simple saves with the extra layer of safety.\n\n`save ( byRef data as String, f as FolderItem, checkIfExists as CheckIfAlreadyExists = CheckIfAlreadyExists.Yes )`\n\n`save ( json as JSONItem, f as FolderItem, checkIfExists as CheckIfAlreadyExists = CheckIfAlreadyExists.Yes )`\n\n`save ( xml as XMLDocument, f as FolderItem, checkIfExists as CheckIfAlreadyExists = CheckIfAlreadyExists.Yes )`\n\n... and ...\n\n`safeSave ( byRef data as String, f as FolderItem, checkIfExists as CheckIfAlreadyExists, leaveTempFile as LeaveTempFileFlag = LeaveTempFileFlag.No )`\n\n`safeSave ( json as JSONItem, f as FolderItem, checkIfExists as CheckIfAlreadyExists, leaveTempFile as LeaveTempFileFlag = LeaveTempFileFlag.No )`\n  \n`safeSave ( xml as XMLDocument, f as FolderItem, checkIfExists as CheckIfAlreadyExists, leaveTempFile as LeaveTempFileFlag = LeaveTempFileFlag.No )`\n\nThere are also matching `load` methods which are really only there for the sake of completeness.\n\n(As is the `moveToTrash` method, which only works on files being trashed from the user’s system/home drive.)\n\nAll of this is macOS only, with no attempt to adapt it for other platforms. The main file support is for text files and JSON files only, as that’s really all I wanted/needed. (I’m not sure why I bothered with the XML support, I thought it was going to see some action but in the end it never did.)\n\nThere’s a simple template mechanism for customising the naming of the temp files: check out `expandFileNameTemplate` for more on that.\n\nThere’s still a few bits to complete here and there, but I wanted to get the main bits done as quickly as possible, as I’ve been using the same save methods for years now, and always intended to get this sorted out but somehow never seemed to get around to doing it. Until now.\n\nI had the vague idea of there being a callback once the initial temp save was done, to allow some form of “verification” of what had been written to take place, before the final step. I’m really not sure how useful/neccessary such a thing would be, so at the moment it’s just been marked as a `// TODO`.\n\nWhen I get a moment I’ll sort out the move to trash so that it uses the correct system API calls (`recycleURLs:completionHandler:`), rather than being the bodge it is at the moment.\n\nhttps://developer.apple.com/documentation/appkit/nsworkspace/recycle(_:completionhandler:)?language=objc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlierobin%2Fsafer-saving-of-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlierobin%2Fsafer-saving-of-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlierobin%2Fsafer-saving-of-files/lists"}