1
0
forked from Mirror/wren

Docs for the io module!

This commit is contained in:
Bob Nystrom
2015-12-29 21:56:44 -08:00
parent 678251a00c
commit 8854dfb07e
6 changed files with 84 additions and 7 deletions

View 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.

View File

@ -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.)

View File

@ -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)

View File

@ -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.

View File

@ -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>

View File

@ -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)
}