Merge pull request #19 from JaapWijnen/filehandle-extensions
added extension to initialize filehandle from path
This commit is contained in:
@@ -86,3 +86,24 @@ public extension Data {
|
||||
return to
|
||||
}
|
||||
}
|
||||
|
||||
/// Extensions on `FileHandle` that work with `Path` rather than `String` or `URL`
|
||||
public extension FileHandle {
|
||||
/// Initializes this `FileHandle` for reading at the location of the provided path.
|
||||
@inlinable
|
||||
convenience init(forReadingAt path: Path) throws {
|
||||
try self.init(forReadingFrom: path.url)
|
||||
}
|
||||
|
||||
/// Initializes this `FileHandle` for writing at the location of the provided path.
|
||||
@inlinable
|
||||
convenience init(forWritingAt path: Path) throws {
|
||||
try self.init(forWritingTo: path.url)
|
||||
}
|
||||
|
||||
/// Initializes this `FileHandle` for reading and writing at the location of the provided path.
|
||||
@inlinable
|
||||
convenience init(forUpdatingAt path: Path) throws {
|
||||
try self.init(forUpdating: path.url)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user