I have a Data struct whose contents (essentially an array of UInt8) represent the contents of an (arbitrarily large) file on storage. The data is character data and I want to be able to iterate over the data one Character at a time (as opposed to one UInt8 at a time). I do not want to convert the data to a String, as this could potentially consume a lot of memory (the Data object was creates using mappedIfSafe to try to minimise memory usage). Anyone have any thoughts on how I might achieve this?
Asked
Active
Viewed 394 times
0
-
If you have a struct which has properties of type Data and UInt8 and a file it would make sense to show the code for that struct and data and property and file. It makes it much easier to see how it could be updated to help you out. – Fogmeister Dec 23 '21 at 15:21
-
I assume you also know the encoding? – Sweeper Dec 23 '21 at 15:26
-
Sounds like you are reading a file? If so, does [this](https://stackoverflow.com/questions/67920038/swift-5-5-asynchronously-iterating-line-by-line-through-a-file) help? Rather than using the `AsyncBytes.lines`, use `characters` instead. – Sweeper Dec 23 '21 at 15:43