0001    // FileStream.swift
0002    //
0003    // The MIT License (MIT)
0004    //
0005    // Copyright (c) 2015 Zewo
0006    //
0007    // Permission is hereby granted, free of charge, to any person obtaining a copy
0008    // of this software and associated documentation files (the "Software"), to deal
0009    // in the Software without restriction, including without limitation the rights
0010    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0011    // copies of the Software, and to permit persons to whom the Software is
0012    // furnished to do so, subject to the following conditions:
0013    //
0014    // The above copyright notice and this permission notice shall be included in all
0015    // copies or substantial portions of the Software.
0016    //
0017    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0018    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0019    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0020    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0021    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0022    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0023    // SOFTWARE.
0024    
0025    @_exported import Stream
0026    
0027    public final class FileStream: StreamType {
0028        private let file
FileStream.swift:35
        return file.closed
FileStream.swift:39
        self.file = file
FileStream.swift:47
            if file.eof {
FileStream.swift:48
                file.close()
FileStream.swift:83
        return file.close()
: File 0029 public let metadata: [String: Any] = [:] 0030 0031 public var lowWaterMark
FileStream.swift:40
        self.lowWaterMark = lowWaterMark
: Int 0032 public var highWaterMark
FileStream.swift:41
        self.highWaterMark = highWaterMark
: Int 0033 0034 public var closed
FileStream.swift:87
        if closed {
: Bool { 0035 return file.closed 0036 } 0037 0038 public init(file: File, lowWaterMark: Int = 1, highWaterMark: Int = 4096) { 0039 self.file = file 0040 self.lowWaterMark = lowWaterMark 0041 self.highWaterMark = highWaterMark 0042 } 0043 0044 public func receive() throws -> Data { 0045 try assertNotClosed() 0046 do { 0047 if file.eof { 0048 file.close() 0049 return [] 0050 } else { 0051 return try file.read(lowWaterMark: lowWaterMark, highWaterMark: highWaterMark) 0052 } 0053 } catch FileError.ConnectionResetByPeer(_, let data) { 0054 throw StreamError.ClosedStream(data: data) 0055 } catch FileError.BrokenPipe(_, let data) { 0056 throw StreamError.ClosedStream(data: data) 0057 } 0058 } 0059 0060 public func send(data: Data) throws { 0061 try assertNotClosed() 0062 do { 0063 try file.write(data, flush: false) 0064 } catch FileError.ConnectionResetByPeer(_, let data) { 0065 throw StreamError.ClosedStream(data: data) 0066 } catch FileError.BrokenPipe(_, let data) { 0067 throw StreamError.ClosedStream(data: data) 0068 } 0069 } 0070 0071 public func flush() throws { 0072 try assertNotClosed() 0073 do { 0074 try file.flush() 0075 } catch FileError.ConnectionResetByPeer(_, let data) { 0076 throw StreamError.ClosedStream(data: data) 0077 } catch FileError.BrokenPipe(_, let data) { 0078 throw StreamError.ClosedStream(data: data) 0079 } 0080 } 0081 0082 public func close() -> Bool { 0083 return file.close() 0084 } 0085 0086 private func assertNotClosed
FileStream.swift:45
        try assertNotClosed()
FileStream.swift:61
        try assertNotClosed()
FileStream.swift:72
        try assertNotClosed()
() throws { 0087 if closed { 0088 throw StreamError.ClosedStream(data: nil) 0089 } 0090 } 0091 }