File: test.lua

package info (click to toggle)
nbdkit 1.42.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,696 kB
  • sloc: ansic: 59,224; sh: 16,793; makefile: 6,463; python: 1,837; cpp: 1,116; ml: 504; perl: 502; tcl: 62
file content (27 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
disk = string.rep ('\0', 1024*1024)

-- Lua strings are indexed from 1, which is crazy.  This is a
-- sane substring function.
function disk_sub (n, len)
   return disk:sub (n+1, n+len)
end

function open (readonly)
   return 1
end

function get_size (h)
   return disk:len()
end

function pread (h, count, offset)
   return disk_sub(offset, count)
end

function pwrite (h, buf, offset)
   -- There's no built-in mutable string type, so this is going
   -- to be very inefficient.
   local count = buf:len()
   local end_len = disk:len() - (offset+count)
   disk = disk_sub(0, offset) .. buf .. disk_sub(offset+count, end_len)
end