Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active January 31, 2021 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/4f2122f4866251bad24df106abbbc565 to your computer and use it in GitHub Desktop.
Save laevandus/4f2122f4866251bad24df106abbbc565 to your computer and use it in GitHub Desktop.
func open() -> Bool {
guard channel == nil else { return true }
guard let path = (fileURL.path as NSString).utf8String else { return false }
channel = DispatchIO(type: .random, path: path, oflag: 0, mode: 0, queue: .main, cleanupHandler: { error in
print("Closed a channel with status: \(error)")
})
// Load the whole requested byte range at once
channel?.setLimit(lowWater: .max)
guard self.channel != nil else { return false }
print("Opened a channel at \(fileURL)")
return true
}
func close() {
channel?.close()
channel = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment