summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadLogging/TextFileOutputStream.swift
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2023-02-03 11:13:59 +0100
committerAndrej Mihajlov <and@mullvad.net>2023-02-03 11:13:59 +0100
commitcdd8439f99243fc4e6fa822f3c6b1d850f4f0104 (patch)
tree14f9571b163d05dd84d8823d85350c3b31d60f7b /ios/MullvadLogging/TextFileOutputStream.swift
parent31c4ff2cc21cd6656f179ea4b261b007f7000cfe (diff)
parent04194a342379c29e17fa07895a57240c8f8877dc (diff)
downloadmullvadvpn-cdd8439f99243fc4e6fa822f3c6b1d850f4f0104.tar.xz
mullvadvpn-cdd8439f99243fc4e6fa822f3c6b1d850f4f0104.zip
Merge branch 'handle-os-boot'
Diffstat (limited to 'ios/MullvadLogging/TextFileOutputStream.swift')
-rw-r--r--ios/MullvadLogging/TextFileOutputStream.swift87
1 files changed, 0 insertions, 87 deletions
diff --git a/ios/MullvadLogging/TextFileOutputStream.swift b/ios/MullvadLogging/TextFileOutputStream.swift
deleted file mode 100644
index 95387b53ec..0000000000
--- a/ios/MullvadLogging/TextFileOutputStream.swift
+++ /dev/null
@@ -1,87 +0,0 @@
-//
-// TextFileOutputStream.swift
-// MullvadVPN
-//
-// Created by pronebird on 02/08/2020.
-// Copyright © 2020 Mullvad VPN AB. All rights reserved.
-//
-
-import Foundation
-
-class TextFileOutputStream: TextOutputStream {
- private let writer: DispatchIO
- private let encoding: String.Encoding
- private let queue = DispatchQueue.global(qos: .utility)
-
- class func standardOutputStream(encoding: String.Encoding = .utf8) -> TextFileOutputStream {
- return TextFileOutputStream(
- fileDescriptor: FileHandle.standardOutput.fileDescriptor,
- encoding: encoding
- )
- }
-
- init(fileDescriptor: Int32, encoding: String.Encoding = .utf8) {
- self.encoding = encoding
- writer = DispatchIO(type: .stream, fileDescriptor: fileDescriptor, queue: queue) { errno in
- if errno != 0 {
- print("TextFileOutputStream: closed channel with error: \(errno)")
- }
- }
- }
-
- init?(
- fileURL: URL,
- createFile: Bool,
- filePermissions: mode_t = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
- encoding: String.Encoding = .utf8
- ) {
- var oflag: Int32 = O_WRONLY
- var mode: mode_t = .zero
- if createFile {
- oflag |= O_CREAT
- mode = filePermissions
- }
-
- let queue = queue
- let writer = fileURL.path.withCString { filePathPointer -> DispatchIO? in
- return DispatchIO(
- type: .stream,
- path: filePathPointer,
- oflag: oflag,
- mode: mode,
- queue: queue,
- cleanupHandler: { errno in
- if errno != 0 {
- print("TextFileOutputStream: closed channel with error: \(errno)")
- }
- }
- )
- }
-
- if let writer = writer {
- self.writer = writer
- self.encoding = encoding
- } else {
- return nil
- }
- }
-
- deinit {
- writer.close()
- }
-
- func write(_ string: String) {
- string.data(using: encoding)?.withUnsafeBytes { bytes in
- writer
- .write(
- offset: .zero,
- data: DispatchData(bytes: bytes),
- queue: queue
- ) { done, data, errno in
- if errno != 0 {
- print("TextFileOutputStream: write error: \(errno)")
- }
- }
- }
- }
-}