Here I think it would be better to accumulate everything in Data and only attempt to decode it when you finally need a string. Then you could (optionally) try multiple encodings and fall back to encoding-repairing conversion by appending a nul character and using String.decodeCString(p, as: UTF8.self, repairingInvalidCodeUnits: true).
|
guard let string = String(data: fileHandle.availableData, encoding: .utf8) else { return } |