Last active
December 3, 2020 15:01
-
-
Save derpoliuk/8683659865ae7d7e6b280c5c27c89784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct DataError: Error { | |
let message = "DataError" | |
} | |
func formatData(_ data: Data) throws -> Data { | |
if Bool.random() { | |
return data | |
} else { | |
throw DataError() | |
} | |
} | |
/// Append Data to URL | |
/// | |
/// - Parameters: | |
/// - data: Date | |
/// - file: Url | |
func append(data: Data, to file: URL) { | |
let handle = try! FileHandle(forUpdating: file) | |
let formattedData = try! formatData(data) | |
handle.seekToEndOfFile() | |
handle.write(formattedData) | |
handle.closeFile() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment