mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Docs for the io module!
This commit is contained in:
10
doc/site/modules/io/directory.markdown
Normal file
10
doc/site/modules/io/directory.markdown
Normal file
@ -0,0 +1,10 @@
|
||||
^title Directory Class
|
||||
|
||||
A directory on the file system.
|
||||
|
||||
## Static Methods
|
||||
|
||||
### Directory.**list**(path)
|
||||
|
||||
Lists the contents of the directory at `path`. Returns a sorted list of path
|
||||
strings for all of the contents of the directory.
|
||||
@ -1,7 +1,66 @@
|
||||
^title File Class
|
||||
|
||||
**TODO**
|
||||
Lets you work with files on the file system. An instance of this class
|
||||
represents an open file with a file descriptor.
|
||||
|
||||
When you are done with a file object, it's a good idea to explicitly close it.
|
||||
If you don't, the GC will close it when the file is no longer used and gets
|
||||
finalized, but that may take a while. In the meantime, leaving it open wastes
|
||||
a file descriptor.
|
||||
|
||||
## Static Methods
|
||||
|
||||
### File.**open**(path, fn)
|
||||
|
||||
Opens the file at [path] and passes it to [fn]. After the function returns, the
|
||||
file is automatically closed.
|
||||
|
||||
:::wren
|
||||
File.open("words.txt") {|file|
|
||||
file.readBytes(5)
|
||||
}
|
||||
|
||||
### File.**read**(path)
|
||||
|
||||
Reads the entire contents of the file at [path] and returns it as a string.
|
||||
|
||||
:::wren
|
||||
File.read("words.txt")
|
||||
|
||||
The encoding or decoding is done. If the file is UTF-8, then the resulting
|
||||
string will be a UTF-8 string. Otherwise, it will be a string of bytes in
|
||||
whatever encoding the file uses.
|
||||
|
||||
### File.**size**(path)
|
||||
|
||||
Returns the size in bytes of the contents of the file at [path].
|
||||
|
||||
## Constructors
|
||||
|
||||
### File.**open**(path)
|
||||
|
||||
Opens the file at [path] for reading.
|
||||
|
||||
## Methods
|
||||
|
||||
**TODO**
|
||||
### **descriptor**
|
||||
|
||||
The numeric file descriptor used to access the file.
|
||||
|
||||
### **isOpen**
|
||||
|
||||
Whether the file is still open or has been closed.
|
||||
|
||||
### **size**
|
||||
|
||||
The size of the contents of the file in bytes.
|
||||
|
||||
### **close**()
|
||||
|
||||
Closes the file. After calling this, you can read or write from it.
|
||||
|
||||
### **readBytes**(count)
|
||||
|
||||
Reads up to [count] bytes starting from the beginning of the file.
|
||||
|
||||
(Allowing an offset to read elsewhere from the file isn't implemented yet.)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
^title Module "io"
|
||||
|
||||
**TODO**
|
||||
Provides access to operating system streams and the file system.
|
||||
|
||||
* [Directory](directory.html)
|
||||
* [File](file.html)
|
||||
* [Stdin](stdin.html)
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
^title Stdin Class
|
||||
|
||||
**TODO**
|
||||
The standard input stream.
|
||||
|
||||
## Methods
|
||||
## Static Methods
|
||||
|
||||
**TODO**
|
||||
### **readLine**()
|
||||
|
||||
Reads one line of input from stdin. Blocks the current fiber until a full line
|
||||
of input has been received.
|
||||
|
||||
Returns the string of input or `null` if stdin is closed.
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
<section>
|
||||
<h2>io classes</h2>
|
||||
<ul>
|
||||
<li><a href="directory.html">Directory</a></li>
|
||||
<li><a href="file.html">File</a></li>
|
||||
<li><a href="stdin.html">Stdin</a></li>
|
||||
</ul>
|
||||
|
||||
@ -51,6 +51,8 @@ foreign class File {
|
||||
Scheduler.runNextScheduled_()
|
||||
}
|
||||
|
||||
foreign descriptor
|
||||
|
||||
isOpen { descriptor != -1 }
|
||||
|
||||
size {
|
||||
@ -74,7 +76,6 @@ foreign class File {
|
||||
foreign static sizePath_(path, fiber)
|
||||
|
||||
foreign close_(fiber)
|
||||
foreign descriptor
|
||||
foreign readBytes_(count, fiber)
|
||||
foreign size_(fiber)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user