forked from rjpcomputing/luaforwindows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileStream.lua
More file actions
executable file
·48 lines (41 loc) · 1.79 KB
/
FileStream.lua
File metadata and controls
executable file
·48 lines (41 loc) · 1.79 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--------------------------------------------------------------------------------
---------------------- ## ##### ##### ###### -----------------------
---------------------- ## ## ## ## ## ## ## -----------------------
---------------------- ## ## ## ## ## ###### -----------------------
---------------------- ## ## ## ## ## ## -----------------------
---------------------- ###### ##### ##### ## -----------------------
---------------------- -----------------------
----------------------- Lua Object-Oriented Programming ------------------------
--------------------------------------------------------------------------------
-- Project: LOOP Class Library --
-- Release: 2.3 beta --
-- Title : Stream that Serializes and Restores Values from Files --
-- Author : Renato Maia <[email protected]> --
--------------------------------------------------------------------------------
local assert = assert
local table = require "table"
local oo = require "loop.simple"
local Serializer = require "loop.serial.Serializer"
module"loop.serial.FileStream"
oo.class(_M, Serializer)
buffersize = 1024
function write(self, ...)
self.file:write(...)
end
function put(self, ...)
self:serialize(...)
self.file:write("\0")
end
function get(self)
local lines = {}
local line
repeat
line = self.remains or self.file:read(self.buffersize)
self.remains = nil
if line and line:find("%z") then
line, self.remains = line:match("^([^%z]*)%z(.*)$")
end
lines[#lines+1] = line
until not line or self.remains
return assert(self:load("return "..table.concat(lines)))()
end