From 49247af11458c47ed2681771aa04e0a08396dbc2 Mon Sep 17 00:00:00 2001 From: Konstantin Iurrichev Date: Thu, 17 Oct 2024 20:47:17 +0300 Subject: [PATCH 1/2] Encode log data to ascii string using c string pointer Signed-off-by: Konstantin Iurrichev --- Sources/XCLogParser/loglocation/LogLoader.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/XCLogParser/loglocation/LogLoader.swift b/Sources/XCLogParser/loglocation/LogLoader.swift index 4a39b88..3d8e946 100644 --- a/Sources/XCLogParser/loglocation/LogLoader.swift +++ b/Sources/XCLogParser/loglocation/LogLoader.swift @@ -26,7 +26,17 @@ public struct LogLoader { do { let data = try Data(contentsOf: url) let unzipped = try data.gunzipped() - guard let contents = String(data: unzipped, encoding: .ascii) else { + let string: String? = unzipped.withUnsafeBytes { pointer in + guard let charPointer = pointer + .assumingMemoryBound(to: CChar.self) + .baseAddress + else { + return nil + } + + return String(cString: charPointer, encoding: .ascii) + } + guard let contents = string else { throw LogError.readingFile(url.path) } return contents From 987ee78282cd00c5e5b8fad554091c2ebb1eda1b Mon Sep 17 00:00:00 2001 From: memoto Date: Wed, 18 Dec 2024 11:45:25 +0100 Subject: [PATCH 2/2] Fix linting Co-authored-by: Daeho Ro Signed-off-by: memoto --- Sources/XCLogParser/loglocation/LogLoader.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XCLogParser/loglocation/LogLoader.swift b/Sources/XCLogParser/loglocation/LogLoader.swift index 3d8e946..4465c57 100644 --- a/Sources/XCLogParser/loglocation/LogLoader.swift +++ b/Sources/XCLogParser/loglocation/LogLoader.swift @@ -29,7 +29,7 @@ public struct LogLoader { let string: String? = unzipped.withUnsafeBytes { pointer in guard let charPointer = pointer .assumingMemoryBound(to: CChar.self) - .baseAddress + .baseAddress else { return nil }