Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
nbdkit/tests/test.lua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 lines (22 sloc)
631 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |