more core docs
[io.git] / libs / iovm / io / File.io
blob68dfe9a1ce23f3e146d88bb30e25cfdaab19d816
1 File do(
2 docSlot("with(aPath)", "Returns a new instance with the provided path.")
3 with := method(path, self clone setPath(path))
5 newSlot("streamDestination")
6 newSlot("streamReadSize", 1024*64)
7 startStreaming := method(streamTo(streamDestination))
9 streamTo := method(streamDestination,
10 b := Sequence clone
11 self open
12 while(isAtEnd not,
13 b empty
14 readToBufferLength(b, streamReadSize)
15 streamDestination write(b)
16 yield
20 copyToPath := method(dstPath,
21 dst := File with(dstPath) open
22 self open streamTo(dst)
23 dst close
24 self close
27 lockFile := method(File clone setPath(path .. ".lock"))
29 lock := method(timeout,
30 if(timeout == nil, timeout = 10)
31 lockFile := lockFile
32 waitTime := .1
33 waited := 0
34 while(lockFile exists,
35 wait(waitTime)
36 waited = waited + waitTime
37 if(waited > timeout, Exception raise("unable to acquire lock on " .. path))
39 lockFile open close
42 unlock := method(lockFile remove)
44 setContents := method(d, self open write(d) close)
47 Sequence do(
48 docSlot("asFile", "Returns a new File object with the receiver as it's path.")
49 asFile := method(
50 File with(self)