Skip to content

Instantly share code, notes, and snippets.

@mike-neko
Created October 10, 2017 14:49
Show Gist options
  • Save mike-neko/6149430f06501b5db9c89aeaf103d5e8 to your computer and use it in GitHub Desktop.
Save mike-neko/6149430f06501b5db9c89aeaf103d5e8 to your computer and use it in GitHub Desktop.
func write(url: URL, text: String) -> Bool {
guard let stream = OutputStream(url: url, append: true) else {
return false
}
stream.open()
defer {
stream.close()
}
guard let data = text.data(using: .utf8) else { return false }
let result = data.withUnsafeBytes {
stream.write($0, maxLength: data.count)
}
return (result > 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment