Skip to content

Commit d922247

Browse files
committed
Implement FileHandle.nullDevice
1 parent 6651025 commit d922247

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Foundation/NSFileHandle.swift

100644100755
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,15 @@ extension FileHandle {
214214
open class var standardError: FileHandle {
215215
return _stderrFileHandle
216216
}
217-
217+
218+
internal static var _nulldeviceFileHandle: FileHandle = {
219+
return FileHandle(forUpdatingAtPath: "/dev/null")!
220+
}()
221+
218222
open class var nullDevice: FileHandle {
219-
NSUnimplemented()
223+
return _nulldeviceFileHandle
220224
}
221-
225+
222226
public convenience init?(forReadingAtPath path: String) {
223227
self.init(path: path, flags: O_RDONLY, createMode: 0)
224228
}

TestFoundation/TestNSFileHandle.swift

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class TestNSFileHandle : XCTestCase {
1919
static var allTests : [(String, (TestNSFileHandle) -> () throws -> ())] {
2020
return [
2121
("test_pipe", test_pipe),
22+
("test_nullDevice", test_nullDevice),
2223
]
2324
}
2425

@@ -38,4 +39,13 @@ class TestNSFileHandle : XCTestCase {
3839
XCTAssertEqual(output, input)
3940
}
4041
}
42+
43+
func test_nullDevice() {
44+
let fh = FileHandle.nullDevice
45+
46+
fh.write(Data(bytes: [1,2]))
47+
XCTAssertEqual(fh.availableData.count, 0)
48+
fh.seek(toFileOffset: 0)
49+
XCTAssertEqual(fh.readDataToEndOfFile().count, 0)
50+
}
4151
}

0 commit comments

Comments
 (0)