Does io.open load the file into memory?

I wanted to know if io.open loads the whole file into memory? Or if it loads it into memory at all.

I am using network.download to save a video file “video.mp4” to the documents directory. But, I also need to allow the user to purge/delete this video file (or multiple files) but there is no direct way of doing that. So what I came up with is to save a small text file with the text “PURGED” but name it with the same name as the video file “video.mp4”.

So now a 30MB video file “video.mp4” is a 4K text file named “video.mp4”

This works great for me.

Now I want to check to see if video.mp4 is my dummy text file or the real thing, so I am looking to use io.open and file:read( 6 ) to read the first six characters of the file. BUT, if io.open loads the whole thing into memory and it happens to be the real video file I might run into some memory issues. Plus, I just dont want to load the whole file in.

So, does io.open just identify/prep the file to be read or does it actually load the whole thing in?

  • davey [import]uid: 7845 topic_id: 12967 reply_id: 312967[/import]

io.open does not load the contents of any file into memory. it just opens the file, does not load it into memory.

file:read using *l reads line, if you use *a it will read the whole file !!! and that you don’t want to do. :wink:

see :: http://lua-users.org/lists/lua-l/2008-10/msg00090.html for a quick sample usage. [import]uid: 24 topic_id: 12967 reply_id: 47898[/import]

Perfect, just the information and answer I was hoping for.

[import]uid: 7845 topic_id: 12967 reply_id: 47901[/import]