1 disk
= string.rep ('\0', 1024*1024)
3 -- Lua strings are indexed from 1, which is crazy. This is a
4 -- sane substring function.
5 function disk_sub (n
, len
)
6 return disk
:sub (n
+1, n
+len
)
9 function open (readonly
)
17 function pread (h
, count
, offset
)
18 return disk_sub(offset
, count
)
21 function pwrite (h
, buf
, offset
)
22 -- There's no built-in mutable string type, so this is going
23 -- to be very inefficient.
24 local count
= buf
:len()
25 local end_len
= disk
:len() - (offset
+count
)
26 disk
= disk_sub(0, offset
) .. buf
.. disk_sub(offset
+count
, end_len
)