-
Notifications
You must be signed in to change notification settings - Fork 4
sys.fs
TurtleKitty edited this page Jan 29, 2016
·
2 revisions
This object exists to interact with the local file system.
read and write open the given pathname as a port.
from and to each accept a path and a procedure of one variable that will be passed the opened port.
mv, cp, ln, rm, stat, pwd, cd, chroot, ls, mkdir, rmdir, are gateways to their Linux equivalents.
tmp-dir behaves like mktmp -d.
listen creates a unix socket listener. connect connects to a unix socket. socket-pair returns a pair of connected sockets.
exists? returns true if a file exists.
dir? returns true if the path is a directory.
symlink? returns true if the path is a symlink. For real.
(sys.fs.read "foo.txt")
-> #<input port "foo.txt"\>
(sys.fs.write "foo.txt")
-> #<output port "foo.txt">
(def tmp sys.fs.tmp)
-> "/tmp/tempb737.13031.tmp"
(def nu-tmp "/tmp/tmp.txt")
(def fbb "/tmp/foobarbaz.txt")
(sys.fs.to
tmp
(proc (p)
(p.write '(foo bar baz))
p.flush))
-> null
(sys.fs.from
tmp
(proc (p)
p.to-text))
-> "(foo bar baz)"
(sys.fs.stat tmp)
-> (vector:
74704580
33188
1
1000
1000
13
1439126396.0
1439126398.0
1439126398.0
31
0
4096
8)
(sys.fs.mv tmp nu-tmp)
-> 13 ; runes transferred
(sys.fs.cp nu-tmp fbb)
-> 13
(sys.fs.ln fbb "/tmp/fbb.txt")
-> null
(sys.fs.symlink? fbb)
-> false
(sys.fs.symlink? "/tmp/fbb.txt")
-> true
(sys.fs.rm nu-tmp)
-> null
(sys.fs.rm fbb)
-> null
(sys.fs.rm "/tmp.fbb.txt")
-> null
sys.fs.pwd
-> "/home/turtlekitty/dev/sexy"
(def t sys.fs.tmp-dir)
-> "/tmp/tempcbec.4412"
(sys.fs.cd t)
-> null
(sys.fs.mkdir "foo")
-> null
(def t-foo (cat t "foo" with: "/"))
-> "/tmp/tempcbec.4412/foo"
(sys.fs.ls t)
-> ("foo")
(sys.fs.ls t-foo)
-> ()
(sys.fs.rmdir t-foo)
-> null
(sys.fs.ls t)
-> ()
(def tmp-sock sys.fs.tmp)
-> "/tmp/temp2133.9373.tmp"
(def server (sys.fs.listen tmp-sock))
-> (fs-listener "/tmp/temp2133.9373.tmp")
(def client (sys.fs.connect tmp-sock))
-> (socket "/tmp/temp2133.9373.tmp")
(def s-sock server.accept)
-> (socket "/tmp/temp2133.9373.tmp")
(s-sock.say "Yo.")
-> null
client.read-line
-> "Yo."
(def socks sys.fs.socket-pair)
-> (pair: (socket ?) (socket ?))
(socks.head.say "Hi!")
-> null
socks.tail.read-line
-> "Hi!"