lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


hi all.

I use gzio for binary data save and restore. but I fount I can't read
a whole file that I have just written into file!

the program is:

require "gzio"

local filename = "test.txt"
local gzFile

-- stream the text file into a gzip file
gzFile = assert(gzio.open(filename..".gz", "w"))
gzFile:write("abc\ndef\nghi")
gzFile:close()

-- echo the gzip file to stdout
gzFile = assert(gzio.open(filename..".gz", "r"), "gzio.open failed!")
for line in gzFile:lines() do
	print(line)
end

-- rewind and do it again with gzFile:read
gzFile:seek("set")
print(gzFile:read("*a"))

gzFile:close()

notice the reopen line:
gzFile = assert(gzio.open(filename..".gz", "r"), "gzio.open failed!")

it's:
gzFile = assert(gzio.open(filename, "r"), "gzio.open failed!")

so in example program, it works well (it opens origin file!)

but if I open filename..".gz", it success, but if I read whole file
(gzFile:read('*a')), the program faults:
nil     No such file or directory       2

but I use lines/read('*l')/read(n) can read file success.

It's strange, but I'm on Windows now, can't compile a dll and debug,
has anybody found this issue before?

btw, this module is on luaforge, and dist together with luaforwindows.