server/public.c: Rearrange functions.
[nbdkit/ericb.git] / tests / test.lua
blobe3bd42135d65b4500da43b78985e2129e646b06c
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)
7 end
9 function open (readonly)
10 return 1
11 end
13 function get_size (h)
14 return disk:len()
15 end
17 function pread (h, count, offset)
18 return disk_sub(offset, count)
19 end
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)
27 end