def read(length = nil, filter = nil, &block)
            buffer = ""
            pos = 0
            
            # Arguments
            if length.kind_of? Proc
                filter = length
            end
            
            
            worker = Proc::new do
            
                # Sets length for read
                if not length.nil?
                    rlen = length - buffer.length
                    if rlen > @rw_len
                        rlen = @rw_len
                    end
                else
                    rlen = @rw_len
                end
                
                # Reads
                begin
                    chunk = @native.read(rlen)
                    if not filter.nil?
                        chunk = filter.call(chunk)
                    end
                    buffer << chunk
                rescue Errno::EBADF
                    if @native.kind_of? ::File
                        self.reopen!
                        @native.seek(pos)
                        redo
                    else
                        raise
                    end
                end
                
                pos = @native.pos
                
                # Returns or continues work
                if @native.eof? or (buffer.length == length)
                    if not block.nil?
                        yield buffer              # returns result
                    end
                else
                    EM::next_tick { worker.call() }     # continues work
                end
                
            end
            
            worker.call()
        end
def read(length = nil, filter = nil, &block)
            buffer = ""
            pos = 0
            
            # Arguments
            if length.kind_of? Proc
                filter = length
            end
            
            
            worker = Proc::new do
            
                # Sets length for read
                if not length.nil?
                    rlen = length - buffer.length
                    if rlen > @rw_len
                        rlen = @rw_len
                    end
                else
                    rlen = @rw_len
                end
                
                # Reads
                begin
                    chunk = @native.read(rlen)
                    if not filter.nil?
                        chunk = filter.call(chunk)
                    end
                    buffer << chunk
                rescue Errno::EBADF
                    if @native.kind_of? ::File
                        self.reopen!
                        @native.seek(pos)
                        redo
                    else
                        raise
                    end
                end
                
                pos = @native.pos
                
                # Returns or continues work
                if @native.eof? or (buffer.length == length)
                    if not block.nil?
                        yield buffer              # returns result
                    end
                else
                    EM::next_tick { worker.call() }     # continues work
                end
                
            end
            
            worker.call()
        end
Constructor. If IO object is given instead of filepath, uses
 it as native one and +mode+ argument is ignored.

 @param [String, IO, StringIO] filepath path to file or IO object
 @param [String] mode file access mode (see equivalent Ruby method)
 @param [Integer] rwsize size of block operated during one tick


 Reads data from file.

 It will reopen the file if +EBADF: Bad file descriptor+ of
 +File+ class IO object will occur.

 @overload read(length, &block)
   Reads specified amount of data from file.
   @param [Integer] length length for read from file
   @param [Proc] filter filter which for postprocessing each
       read chunk
   @param [Proc] block callback for returning the result
   @yield [String] read data
 @overload read(&block)
   Reads whole content of file.
   @param [Proc] filter filter which for processing each block
   @param [Proc] block callback for returning the result
   @yield [String] read data