Jump to content

[Solved] Stream write needs a flush or close


Roland
 Share

Recommended Posts

When writing to a file using FileSystem/Stream the content is not flushed to disk directly when the filehandler is set to nil. A close() or flush() function would be a solution to this. Here is my test

 

-- FILE IO TEST
local fw = FileSystem:WriteFile("test.bin")
if fw ~= nil then
System:Print( "*** FILE WRITE" )
fw:WriteInt(12345)
fw = nil
end

local fr = FileSystem:ReadFile("test.bin")
if fr ~= nil then
local value = fr:ReadInt()
System:Print("*** FILE READ = " .. value )
fr = nil
end

 

The result

 

=====================================================

*** FILE WRITE

*** FILE READ = 0

=====================================================

 

 

After the program has finished the content is 12345 as it should be.

 

Here is the same with LUA io-operations which works

 

--- FILE IO TEST
local fw = io.open("test.bin", "wb")
if fw ~= nil then
System:Print( "*** FILE WRITE" )
fw:write(12345)
fw:close()
end

local fr = io.open("test.bin", "rb")
if fr ~= nil then
local value = fr:read()
System:Print("*** FILE READ = " .. value )
fr:close()
end

 

and the correct result

 

 

=====================================================

*** FILE WRITE

*** FILE READ = 12345

=====================================================

AV MX Linux

Link to comment
Share on other sites

Does calling :Release() on fw work?

Yes that worked. Thanks .. how in the heck could I forget about Release wink.png I'm soon in that age when it could be explained by dementia.

 

Guess this is kind of solved then

  • Upvote 2

AV MX Linux

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...