From: Yohanes Santoso Date: 2002-03-13T10:18:57+09:00 Subject: Re: gzip again... Dave Thomas writes: > > You're writing 100k in one chunk. gzip starts reading it, and after > reading 50k it has enough data to start writing some output. Perhaps > it has 200k to write to you. However, you're still busy writing, and > don't yet have a read pending, so gzip will be suspended. The result > is that both sides will be deadlocked. This is why you cannot use IO.popen without setting O_NONBLOCK. You got to either use popen3 and select, or thread, although I doubt thread will work if you dont set O_NONBLOCK to the pipe returned by IO.popen. Since I don't know how to pass O_NONBLOCK to IO.fcntl, then the following is an implementation using the popen3&select method, which may or may not work. May require some tweaking to get it working. I don't have ruby here. It's not very efficient, working a byte at a time, but I see no alternatives without O_NONBLOCK. If it had been writting even two bytes at a time, there is no guarantee that the IO won't block while writting the second byte. So conclusion is, yeah, you need O_NONBLOCK. Does someone know how to use O_NONBLOCK in IO.fcntl? data = File.open('blabala.gz') {|f| f.read} File.open("/tmp/test.out", "w") { |file| dataWhere = 0 popen3("gzip -dc") { |ios| i,o,e = ios while ready = select([o],[i]) do if ready[0].length > 0 then file.write(ready[0][0].getc) end if ready[1].length > 0 and dataWhere <= data.length ready[1][0].putc(data[dataWhere]) dataWhere+=1 end end } } YS.