@@ -10,7 +10,7 @@ import kotlinx.io.Sink
10
10
import kotlinx.io.Source
11
11
12
12
/* *
13
- * An interface providing basic operations on a file system .
13
+ * An interface providing basic operations on a filesystem .
14
14
*
15
15
* **This API is unstable and subject to change.**
16
16
*/
@@ -21,7 +21,7 @@ public sealed interface FileSystem {
21
21
public val temporaryDirectory: Path
22
22
23
23
/* *
24
- * Returns `true` if there is a file system entity corresponding to a [path],
24
+ * Returns `true` if there is a filesystem entity a [path] points to ,
25
25
* otherwise returns `false`.
26
26
*
27
27
* @param path the path that should be checked for existence.
@@ -31,15 +31,18 @@ public sealed interface FileSystem {
31
31
public fun exists (path : Path ): Boolean
32
32
33
33
/* *
34
- * Deletes [path] from a file system. If there is no file system entity
35
- * represented by the [path] this method throws [kotlinx.io.files.FileNotFoundException] when [mustExist ]
36
- * is `true`.
34
+ * Deletes a file or directory the [path] points to from a filesystem.
35
+ * If there is no filesystem entity represented by the [path ]
36
+ * this method throws [kotlinx.io.files.FileNotFoundException] when [mustExist] is `true`.
37
37
*
38
- * @param path the path to be deleted.
38
+ * Note that in the case of a directory, this method will not attempt to delete it recursively,
39
+ * so deletion of non-empty directory will fail.
40
+ *
41
+ * @param path the path to a file or directory to be deleted.
39
42
* @param mustExist the flag indicating whether missing [path] is an error, `true` by default.
40
43
*
41
44
* @throws kotlinx.io.files.FileNotFoundException when [path] does not exist and [mustExist] is `true`.
42
- * @throws kotlinx.io.IOException if the [path] could not be deleted .
45
+ * @throws kotlinx.io.IOException if deletion failed .
43
46
*/
44
47
public fun delete (path : Path , mustExist : Boolean = true)
45
48
@@ -48,7 +51,7 @@ public sealed interface FileSystem {
48
51
* If [path] already exists then the method throws [kotlinx.io.IOException] when [mustCreate] is `true`.
49
52
* The call will attempt to create only missing directories.
50
53
* The method is not atomic and if it fails after creating some
51
- * directories these directories will not be deleted automatically.
54
+ * directories, these directories will not be deleted automatically.
52
55
* Permissions for created directories are platform-specific.
53
56
*
54
57
* @param path the path to be created.
@@ -63,26 +66,28 @@ public sealed interface FileSystem {
63
66
/* *
64
67
* Atomically renames [source] to [destination] overriding [destination] if it already exists.
65
68
*
66
- * When the file system does not support atomic move of [source] and [destination] corresponds to different
67
- * file systems and the operation could not be performed atomically,
69
+ * When the filesystem does not support atomic move of [source] and [destination] corresponds to different
70
+ * filesystems and the operation could not be performed atomically,
68
71
* [UnsupportedOperationException] is thrown.
69
72
*
70
73
* @param source the path to rename.
71
74
* @param destination desired path name.
72
75
*
73
76
* @throws kotlinx.io.files.FileNotFoundException when the [source] does not exist.
74
77
* @throws kotlinx.io.IOException when the move failed.
75
- * @throws kotlin.UnsupportedOperationException when the file system does not support atomic move.
78
+ * @throws kotlin.UnsupportedOperationException when the filesystem does not support atomic move.
76
79
*/
77
80
public fun atomicMove (source : Path , destination : Path )
78
81
79
82
/* *
80
- * Returns [Source] to read from a file represented by the [path].
83
+ * Returns [Source] to read from a file the [path] points to .
81
84
*
82
85
* How a source will read the data is implementation-specific and failures caused
83
86
* by the missing file or, for example, lack of permissions may not be reported immediately,
84
87
* but postponed until the source will try to fetch data.
85
88
*
89
+ * If [path] points to a directory, this method will fail with [IOException].
90
+ *
86
91
* @param path the path to read from.
87
92
*
88
93
* @throws kotlinx.io.files.FileNotFoundException when the file does not exist.
@@ -91,19 +96,21 @@ public sealed interface FileSystem {
91
96
public fun read (path : Path ): Source
92
97
93
98
/* *
94
- * Returns [Sink] to write into a file represented by the [path].
99
+ * Returns [Sink] to write into a file the [path] points to .
95
100
* File will be created if it does not exist yet.
96
101
*
97
102
* How a sink will write the data is implementation-specific and failures caused,
98
103
* for example, by the lack of permissions may not be reported immediately,
99
104
* but postponed until the sink will try to store data.
100
105
*
106
+ * If [path] points to a directory, this method will fail with [IOException].
107
+ *
101
108
* @throws kotlinx.io.IOException when it's not possible to open the file for writing.
102
109
*/
103
110
public fun write (path : Path ): Sink
104
111
105
112
/* *
106
- * Return [FileMetadata] associated with a file or directory represented by the [path].
113
+ * Return [FileMetadata] associated with a file or directory the [path] points to .
107
114
* If there is no such file or directory, or it's impossible to fetch metadata,
108
115
* `null` is returned.
109
116
*
@@ -113,7 +120,7 @@ public sealed interface FileSystem {
113
120
114
121
public companion object {
115
122
/* *
116
- * An instance of [FileSystem] representing a default system-wide file system .
123
+ * An instance of [FileSystem] representing a default system-wide filesystem .
117
124
*/
118
125
public val System : FileSystem = SystemFileSystem
119
126
}
@@ -129,6 +136,9 @@ internal abstract class SystemFileSystemImpl : FileSystem {
129
136
130
137
internal expect val SystemFileSystem : FileSystem
131
138
139
+ /* *
140
+ * Represents information about a file or directory obtainable from a filesystem.
141
+ */
132
142
public class FileMetadata (
133
143
/* *
134
144
* Flag indicating that the metadata was retrieved for a regular file.
@@ -144,4 +154,7 @@ public class FileMetadata(
144
154
public val size : Long = 0L
145
155
)
146
156
157
+ /* *
158
+ * Signals an I/O operation's failure due to a missing file or directory.
159
+ */
147
160
public expect class FileNotFoundException (message : String? ) : IOException
0 commit comments