         }
     }
     
-    func readBuffer(buffer: ByteBuffer, inout error: Int) -> Int? {
+    func readBuffer(buffer: ByteBuffer, inout error: Error) -> ByteCount? {
         let bytesRead = read(fileDescriptor, buffer.data + buffer.position, UInt(buffer.remaining))
         
         if (bytesRead < 0) {
-            // error!
-            error = Int(errno)
+            error = Error(code: Int(errno))
             return nil
-        } else if (bytesRead == 0) {
-            // EOF
-            return -1
         } else {
             buffer.position += bytesRead
             return bytesRead
         }
     }
     
-    func writeBuffer(buffer: ByteBuffer, inout error: Int) -> Int? {
+    func writeBuffer(buffer: ByteBuffer, inout error: Error) -> ByteCount? {
         let bytesWritten = write(fileDescriptor, buffer.data + buffer.position, UInt(buffer.remaining))
         
         if (bytesWritten < 0) {
-            error = Int(errno)
+            error = Error(code: Int(errno))
             return nil
         } else {
             buffer.position += bytesWritten

        }
    }
    
    func seekFromStart(offset: Int) {
        let result = lseek(fileDescriptor, off_t(offset), SEEK_SET)
        if (result == -1) {
            // error!
        }
    }
    
    func seekFromCurrent(offset: Int) {
        let result = lseek(fileDescriptor, off_t(offset), SEEK_CUR)
        if (result == -1) {
            // error!
        }
    }
    
    func seekFromEnd(offset: Int) {
        let result = lseek(fileDescriptor, off_t(offset), SEEK_END)
        if (result == -1) {
            // error!
        }
    }
}

// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

typealias Offset = off_t
typealias ByteCount = ssize_t

class BinaryFile {
    let fileDescriptor: CInt
