@@ -70,44 +70,14 @@ DIRECTORY-SYMBOLIC-LINK ::= 7
7070An open file with a current position. Corresponds in many ways to a file
7171 descriptor in Posix.
7272*/
73- class Stream_
73+ class OpenFile_
7474 extends Object
7575 with io.CloseableInMixin io.CloseableOutMixin
7676 implements Stream :
7777 fd_ := ?
7878
7979 constructor .internal_ .fd_ :
8080
81- /**
82- Opens the file at $path for reading.
83- */
84- constructor .for-read path / string :
85- return Stream_ path RDONLY 0
86-
87- /**
88- Opens the file at $path for writing.
89-
90- If the file does not exist, it is created. If it exists, it is truncated.
91- Uses the given $permissions, modified by the current umask, to set the
92- permissions of the file.
93-
94- Ignored if the file already exists.
95- */
96- constructor .for-write path / string --permissions / int= ( ( 6 << 6 ) | ( 6 << 3 ) | 6 ) :
97- return Stream_ path ( WRONLY | TRUNC | CREAT ) permissions
98-
99- /**
100- Opens the file at $path with the given $flags.
101-
102- The $flags parameter is a bitwise-or of the flags defined in this package,
103- such as $RDONLY, $WRONLY, $RDWR, $APPEND, $CREAT, and $TRUNC.
104- */
105- constructor path / string flags / int :
106- if ( flags & CREAT ) != 0 :
107- // Two argument version with no permissions can't create new files.
108- throw "INVALID_ARGUMENT"
109- return Stream_ path flags 0
110-
11181 /**
11282 Creates a stream for a file.
11383
@@ -119,7 +89,6 @@ class Stream_
11989 The $permissions parameter is the permissions to use when creating the file,
12090 modified by the current umask. Ignored if the file already exists.
12191 */
122- // Returns an open file. Only for use on actual files, not pipes, devices, etc.
12392 constructor path / string flags / int permissions / int :
12493 fd := null
12594 error := catch :
@@ -128,7 +97,10 @@ class Stream_
12897 if error is string :
12998 throw "$ error : \" $ path\" "
13099 throw error
131- return Stream_ .internal_ fd
100+ fd_ = fd
101+
102+ /** Deprecated. */
103+ fd -> any : return fd_
132104
133105 /**
134106 Reads some data from the file, returning a byte array.
@@ -162,6 +134,7 @@ class Stream_
162134
163135 close -> none :
164136 close_ fd_
137+ fd_ = null
165138
166139 is-a-terminal -> bool :
167140 return false
0 commit comments