From: Bernhard Brodowsky Date: 2012-09-05T02:41:03+09:00 Subject: Re: Socket Decorator Jeremy Bopp wrote in post #1074640: > On 09/04/2012 07:34 AM, Bernhard Brodowsky wrote: >> having to implement all the gets puts send recv etc myself? > Take a look at the io-like gem: > > https://rubygems.org/gems/io-like > > It provides a fairly easy way to emulate the IO interface; however, I > haven't updated it yet to emulate Ruby 1.9 IO details. Ruby 1.8.7 is > the limit for now. > > -Jeremy Thanks a lot, that is almost exactly what I was looking for. But there is a slight twist in my application: I cannot do unbuffered_read() for an arbitrary length in my case because the transformations operate on blocks and my transformations may even change the length of the part I read in an unpredictable way, which makes it impossible in the first place to read a given number of bytes. There is an easy workaround for this, namely that I can use another internal buffer for my transformations and read as much as necessary to achieve a given length, but it is a little inefficient and not very elegant to do so, because then my read operation is not really unbuffered and there exist two buffers on the different layers. A much larger problem is the fact that I usually work with sockets. With sockets, I cannot do "unbuffered_read" for an arbitrarily large length since the other side may simply not have sent enough yet. I didn't look at your implementation yet, but I guess if I call gets, you probably read subsequent larger parts (let's say of size N) using the unbuffered_read operation in some way until you find a newline character. But if the other side just sends "\n", gets should not block, but deliver "\n" directly, but if you try to read N bytes, it would block. So your library seems nice in the case if the underlying IO object is a File or something similar, I guess that is also the application you had in mind when you wrote it, but for sockets, it is probably a little harder. -- Posted via http://www.ruby-forum.com/.