feat: add File.stat() method and Stat class for filesystem metadata queries

Implement asynchronous stat() on File class returning a new Stat object with device, inode, mode, linkCount, user, group, specialDevice, size, blockSize, and blockCount fields populated from libuv uv_fs_stat callback. Register foreign method statPath_ in module registry, bump MAX_METHODS_PER_CLASS to 10, add Stat class to io.wren with indexed field accessors, update documentation index with Stat page, and include test coverage for stat on existing file and nonexistent path.
This commit is contained in:
Bob Nystrom
2016-01-01 17:58:44 +00:00
parent 3746b56ed9
commit f112722d00
11 changed files with 195 additions and 11 deletions
+3 -10
View File
@@ -1,13 +1,6 @@
import "io" for File
import "scheduler" for Scheduler
System.print(File.size("test/io/file/size.wren")) // expect: 270
// Runs asynchronously.
Scheduler.add {
System.print("async")
}
System.print(File.size("test/io/file/size.wren"))
// expect: async
// expect: 270
var file = File.open("test/io/file/file.txt")
System.print(file.size) // expect: 19
file.close()
+13
View File
@@ -0,0 +1,13 @@
import "io" for File
import "scheduler" for Scheduler
System.print(File.size("test/io/file/file.txt")) // expect: 19
// Runs asynchronously.
Scheduler.add {
System.print("async")
}
System.print(File.size("test/io/file/file.txt"))
// expect: async
// expect: 19
+16
View File
@@ -0,0 +1,16 @@
import "io" for File, Stat
import "scheduler" for Scheduler
var stat = File.stat("test/io/file/file.txt")
System.print(stat is Stat) // expect: true
System.print(stat.device is Num) // expect: true
System.print(stat.inode is Num) // expect: true
System.print(stat.mode is Num) // expect: true
System.print(stat.linkCount) // expect: 1
System.print(stat.user is Num) // expect: true
System.print(stat.group is Num) // expect: true
System.print(stat.specialDevice) // expect: 0
System.print(stat.size) // expect: 19
System.print(stat.blockSize is Num) // expect: true
System.print(stat.blockCount is Num) // expect: true
@@ -0,0 +1,3 @@
import "io" for File
File.stat("nonexistent") // expect runtime error: no such file or directory