Skip to content

Commit

Permalink
Added GetLength() to streams interface
Browse files Browse the repository at this point in the history
Added GetPosition() to streams interface
  • Loading branch information
Wiladams committed Jun 12, 2012
1 parent bc52fce commit 8541163
Show file tree
Hide file tree
Showing 5 changed files with 1,647 additions and 7 deletions.
23 changes: 22 additions & 1 deletion FileStream.lua
Expand Up @@ -33,6 +33,19 @@ function FileStream.Open(filename, mode)
end


function FileStream:GetLength()
local currpos = self.FileHandle:seek()
local size = self.FileHandle:seek("end")

self.FileHandle:seek("set",currpos)

return size;
end

function FileStream:GetPosition()
local currpos = self.FileHandle:seek()
return currpos;
end

function FileStream:Seek(offset, origin)
offset = offset or 0
Expand Down Expand Up @@ -80,7 +93,15 @@ end

function FileStream:WriteBytes(buffer, len, offset)
offset = offset or 0
local str = ffi.string(buffer+offset, len)

if type(buffer) == "string" then
self.FileHandle:write(buffer)
return len
end

-- assume we have a pointer to a buffer
-- convert to string and write it out
local str = ffi.string(buffer, len)
self.FileHandle:write(str)

return len
Expand Down
8 changes: 8 additions & 0 deletions MemoryStream.lua
Expand Up @@ -18,6 +18,14 @@ function MemoryStream.new(size, buff)
return obj
end

function MemoryStream:GetLength()
return self.Length
end

function MemoryStream:GetPosition()
return self.Position
end

--[[
Reading interface
--]]
Expand Down

0 comments on commit 8541163

Please sign in to comment.