local struct = require "struct"
local str = require "pl.stringx"
local unpack = struct.unpack
local x = string.x2c
printf = function(...) return io.write(string.format(...)) end
local function pds_dir_iterator(dsname)
local EOF = x'FFFFFFFFFFFFFFFF' local endOfList = false
local pds = assert(io.open(dsname, "rb"))
repeat
local rec = pds:read(256) if not rec then break end
local size, index = unpack("H",rec) while index < size do
local member, ttr, info, userData
member, ttr, info, index = unpack("c8I3I1",rec, index)
if member == EOF then endOfList = true; break
end
local dataSize = bit32.band(info, 0x1F) * 2 if dataSize > 0 then
userData, index = unpack("c"..dataSize, rec, index)
end
coroutine.yield(str.rtrim(member))
end
until endOfList
end
return function (dsname)
return coroutine.wrap(function () pds_dir_iterator(dsname) end)
end