Bluon files: Use "wb" / "rb" instead of "w" / "r"

This commit is contained in:
Lars Mueller 2021-07-13 20:28:44 +02:00
parent f2ecbac112
commit 2ba0b0555f
2 changed files with 5 additions and 5 deletions

@ -111,7 +111,7 @@ Checking whether the stream has been fully consumed by doing `assert(not stream:
```lua ```lua
local object = ... local object = ...
-- Write to file -- Write to file
local file = io.open(..., "w") local file = io.open(..., "wb")
modlib.bluon:write(object, file) modlib.bluon:write(object, file)
file:close() file:close()
-- Write to text -- Write to text

@ -131,7 +131,7 @@ local function write_bluon(self, stream)
end end
function schematic:write_bluon(path) function schematic:write_bluon(path)
local file = io.open(path, "w") local file = io.open(path, "wb")
-- Header, short for "ModLib Bluon Schematic" -- Header, short for "ModLib Bluon Schematic"
file:write"MLBS" file:write"MLBS"
write_bluon(self, file) write_bluon(self, file)
@ -165,13 +165,13 @@ local function read_bluon(file)
end end
function schematic.read_bluon(path) function schematic.read_bluon(path)
local file = io.open(path, "r") local file = io.open(path, "rb")
assert(file:read(4) == "MLBS", "not a modlib bluon schematic") assert(file:read(4) == "MLBS", "not a modlib bluon schematic")
return schematic.setmetatable(read_bluon(file)) return schematic.setmetatable(read_bluon(file))
end end
function schematic:write_zlib_bluon(path, compression) function schematic:write_zlib_bluon(path, compression)
local file = io.open(path, "w") local file = io.open(path, "wb")
-- Header, short for "ModLib Zlib-compressed-bluon Schematic" -- Header, short for "ModLib Zlib-compressed-bluon Schematic"
file:write"MLZS" file:write"MLZS"
local rope = modlib.table.rope{} local rope = modlib.table.rope{}
@ -182,7 +182,7 @@ function schematic:write_zlib_bluon(path, compression)
end end
function schematic.read_zlib_bluon(path) function schematic.read_zlib_bluon(path)
local file = io.open(path, "r") local file = io.open(path, "rb")
assert(file:read(4) == "MLZS", "not a modlib zlib compressed bluon schematic") assert(file:read(4) == "MLZS", "not a modlib zlib compressed bluon schematic")
return schematic.setmetatable(read_bluon(modlib.text.inputstream(minetest.decompress(file:read"*a", "deflate")))) return schematic.setmetatable(read_bluon(modlib.text.inputstream(minetest.decompress(file:read"*a", "deflate"))))
end end