Skip to content

Commit e82ed1d

Browse files
authored
More refactoring. (#85)
1 parent ff81fca commit e82ed1d

File tree

12 files changed

+299
-185
lines changed

12 files changed

+299
-185
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
os: [ ubuntu-latest, windows-latest, macos-latest ]
1313
# The versions should contain (at least) the lowest requirement
1414
# and a version that is more up to date.
15-
toit-version: [ v2.0.0-alpha.144, latest]
15+
toit-version: [ v2.0.0-alpha.170, latest]
1616
include:
17-
- toit-version: v2.0.0-alpha.144
17+
- toit-version: v2.0.0-alpha.170
1818
version-name: old
1919
- toit-version: latest
2020
version-name: new

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: host
22
description: Host libraries for the Toit platform.
33

44
environment:
5-
sdk: ^2.0.0-alpha.144
5+
sdk: ^2.0.0-alpha.170

src/file.toit

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,14 @@ DIRECTORY-SYMBOLIC-LINK ::= 7
7070
An 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

Comments
 (0)