Post

Replies

Boosts

Views

Activity

Reply to Any way to get arbitrary TIFF tags from a file?
Note that this forum would not let me mark up links above. Wow, it also wouldn't let me include the integers for the tile offsets and byte counts in the dump above, saying there was inappropriate language in the post. I had to bisect it and update it multiple times to track down the specific language, as it would not say what it didn't like. Apparently it doesn't like strings of integers Apparently strings of digits look like phone numbers and are rejected. I believe this is how they stop p r o s t i t u t e s from advertising on the forum. As you can see, Apple have more important things to work on than GeoTIFF!
Topic: Media Technologies SubTopic: General Tags:
Jul ’24
Reply to What is the recommended way to count files recursively in a specific folder
Yes I believe you need to recursively descend through the directory tree. So you need to read each directory, determine which of the directory entries are sub-directories, and visit those. This boils down to readdir and stat. I am aware of one possible optimisation, if you want to squeeze the last bit of performance. In order to determine whether a directory entry is a sub-directory, rather than a regular file, in general you need to stat it. But, when you stated the parent directory you got st_nlink, which tells you the number of hard links to that directory. Each directory's .. entry counts as a hard link to its parent directory, and its . entry is a hard link to itself. So if st_nlink is 4, then the directory can have at most 3 subdirectories. So you can enumerate the directory contents, checking if each entry is a subdirectory, until you have found 3. At that point you can stop stating everything - the remaining entries must be non-directories. This is classic UNIX stuff that has worked since forever. It's not impossible that new Apple filesystems have alternative APIs that make this more efficient. Maybe someone else will comment. I don't know where the bottleneck is - is it the disk access speed? - is it the number of kernel calls? Things you need to consider if you want a robust implementation: Hard links Symlinks Hard or symbolic links that introduce cycles Other special directory entries Mount points Whether to include . and .. and other dotfiles in your count Unreadable (and unexecutable) directories Personally, I'd do something like this: auto count_files(std::filesystem::path p) { int n_files = 0; for (auto& entry: std::filesystem::recursive_directory_iterator(p)) { if (is_regular_file(entry)) ++n_files; } return n_files; }
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’24
Reply to XSLT 2.0 transformation with Swift or WKWebView
I wasn't aware that libxslt (and also libexslt apparently) is public on iOS; that's useful to know. (I've used XSLT a fair bit over the years but always on the server side.) You really need to determine whether or not you need XSLT 2 functionality. I suspect that you don't, because a bit of googling finds StackOverflow answers saying that .NET doesn't support XSLT 2. If you actually do... I don't really know what to suggest, except fixing the XSLT to not need the version 2 features. Otherwise, everything boils down to libxslt in the end. So your choice is between Swift -> Javascript -> C -> libxslt -> C -> Javascript -> Swift Swift -> C -> libxslt -> C -> Swift Some of those steps will involve serialising / deserialising XML text to/from XML object representations. Personally, I'd choose the second option. Swift/C interop is pretty good. If you've not done it before - now's your chance to learn! Using a WKWebView is a horrible hack IMO. The usual reason for using WKWebView is that it has JIT Javascript, which JavascriptCore doesn't have, giving a worthwhile performance boost (maybe 10X). But that's not an issue here, as the JIT would just call the native C libxslt to do the work, and you can call that directly.
Jul ’24
Reply to Any way to get arbitrary TIFF tags from a file?
Note that this forum would not let me mark up links above. Wow, it also wouldn't let me include the integers for the tile offsets and byte counts in the dump above, saying there was inappropriate language in the post. I had to bisect it and update it multiple times to track down the specific language, as it would not say what it didn't like. Apparently it doesn't like strings of integers Apparently strings of digits look like phone numbers and are rejected. I believe this is how they stop p r o s t i t u t e s from advertising on the forum. As you can see, Apple have more important things to work on than GeoTIFF!
Topic: Media Technologies SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jul ’24
Reply to What is the recommended way to count files recursively in a specific folder
Yes I believe you need to recursively descend through the directory tree. So you need to read each directory, determine which of the directory entries are sub-directories, and visit those. This boils down to readdir and stat. I am aware of one possible optimisation, if you want to squeeze the last bit of performance. In order to determine whether a directory entry is a sub-directory, rather than a regular file, in general you need to stat it. But, when you stated the parent directory you got st_nlink, which tells you the number of hard links to that directory. Each directory's .. entry counts as a hard link to its parent directory, and its . entry is a hard link to itself. So if st_nlink is 4, then the directory can have at most 3 subdirectories. So you can enumerate the directory contents, checking if each entry is a subdirectory, until you have found 3. At that point you can stop stating everything - the remaining entries must be non-directories. This is classic UNIX stuff that has worked since forever. It's not impossible that new Apple filesystems have alternative APIs that make this more efficient. Maybe someone else will comment. I don't know where the bottleneck is - is it the disk access speed? - is it the number of kernel calls? Things you need to consider if you want a robust implementation: Hard links Symlinks Hard or symbolic links that introduce cycles Other special directory entries Mount points Whether to include . and .. and other dotfiles in your count Unreadable (and unexecutable) directories Personally, I'd do something like this: auto count_files(std::filesystem::path p) { int n_files = 0; for (auto& entry: std::filesystem::recursive_directory_iterator(p)) { if (is_regular_file(entry)) ++n_files; } return n_files; }
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jul ’24
Reply to XSLT 2.0 transformation with Swift or WKWebView
I wasn't aware that libxslt (and also libexslt apparently) is public on iOS; that's useful to know. (I've used XSLT a fair bit over the years but always on the server side.) You really need to determine whether or not you need XSLT 2 functionality. I suspect that you don't, because a bit of googling finds StackOverflow answers saying that .NET doesn't support XSLT 2. If you actually do... I don't really know what to suggest, except fixing the XSLT to not need the version 2 features. Otherwise, everything boils down to libxslt in the end. So your choice is between Swift -> Javascript -> C -> libxslt -> C -> Javascript -> Swift Swift -> C -> libxslt -> C -> Swift Some of those steps will involve serialising / deserialising XML text to/from XML object representations. Personally, I'd choose the second option. Swift/C interop is pretty good. If you've not done it before - now's your chance to learn! Using a WKWebView is a horrible hack IMO. The usual reason for using WKWebView is that it has JIT Javascript, which JavascriptCore doesn't have, giving a worthwhile performance boost (maybe 10X). But that's not an issue here, as the JIT would just call the native C libxslt to do the work, and you can call that directly.
Replies
Boosts
Views
Activity
Jul ’24