ReadableFile
public final class ReadableFile: File, ReadableStream
A class for reading text from a file.
-
The path to the file
Declaration
Swift
public let path: FilePath -
The encoding for the text in the file.
Declaration
Swift
public var encoding: String.Encoding = .utf8 -
The type of file or file-like item this is.
Declaration
Swift
public let type: FileType -
Opens the file at ‘path’ for reading.
Parameter
Parameter path: the path to the file.Throws
FileSystemError.notFound, .isDirectory, .invalidAccess.Declaration
Swift
public convenience init(open path: FilePath) throwsParameters
paththe path to the file.
-
Creates a new ReadableFile which reads from the provided file handle. The path is
/dev/fd/
+ the file handle’s filedescriptor.Declaration
Swift
public convenience init(_ filehandle: FileHandle) -
Reads everything.
Declaration
Swift
public func read() -> String -
Reads whatever amount of text the source feels like providing. If this is a regular file it will read everything at once. - Returns: more text, or nil if we have reached the end.
Declaration
Swift
public func readSome() -> String?Return Value
more text, or nil if we have reached the end.
-
Closes the source. If it is not a regular file it must be closed when finished writing, to prevent deadlock when reading.
Declaration
Swift
public func close() -
A ReadableStream which reads from standard input.
Declaration
Swift
static public var stdin: ReadableStream =
-
handlerwill be called whenever there is new text output available. Passnilto remove any preexisting handlers.Declaration
Swift
public func onOutput(handler: ((String) -> ())? )
View on GitHub
ReadableFile Class Reference