feat: add networking module with TCP Socket/Server and example applications
Implement a full-featured `net` module supporting TCP `Socket` and `Server` classes via libuv, including example applications (chat server, echo server, HTTP client/server, file explorer, system dashboard) and benchmark scripts (fibonacci, n-body). Add GEMINI.md project documentation and Stderr class to io module.
This commit is contained in:
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
import "io" for Directory, File, Stat
|
||||
|
||||
class FileExplorer {
|
||||
static listRecursive(path, depth) {
|
||||
var indent = " " * depth
|
||||
var files = []
|
||||
|
||||
// We wrap Directory.list in a try to handle permission errors
|
||||
var fiber = Fiber.new {
|
||||
files = Directory.list(path)
|
||||
}
|
||||
fiber.try()
|
||||
|
||||
if (fiber.error != null) {
|
||||
System.print("\%(indent)[!] Error accessing \%(path)")
|
||||
return
|
||||
}
|
||||
|
||||
// Sort files manually since String comparison isn't built-in
|
||||
files.sort(Fn.new {|a, b|
|
||||
var ba = a.bytes
|
||||
var bb = b.bytes
|
||||
var len = ba.count < bb.count ? ba.count : bb.count
|
||||
for (i in 0...len) {
|
||||
if (ba[i] < bb[i]) return true
|
||||
if (ba[i] > bb[i]) return false
|
||||
}
|
||||
return ba.count < bb.count
|
||||
})
|
||||
|
||||
for (file in files) {
|
||||
if (file == "." || file == "..") continue
|
||||
|
||||
var fullPath = path + "/" + file
|
||||
if (path == ".") fullPath = "./" + file
|
||||
|
||||
var stat = Stat.path(fullPath)
|
||||
if (stat.isDirectory) {
|
||||
System.print("\%(indent)[D] \%(file)/")
|
||||
listRecursive(fullPath, depth + 1)
|
||||
} else {
|
||||
var size = stat.size
|
||||
var unit = "B"
|
||||
if (size > 1024) {
|
||||
size = size / 1024
|
||||
unit = "KB"
|
||||
}
|
||||
System.print("\%(indent)[F] \%(file) (\%(size.round)\%(unit))")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.print("Recursive directory listing for current path:")
|
||||
System.print("--------------------------------------------")
|
||||
FileExplorer.listRecursive(".", 0)
|
||||
Reference in New Issue
Block a user