def write(data, filter = nil, &block)
            pos = 0
            
            if data.kind_of? IO
                io = data
            else
                io = StringIO::new(data)
            end
            
            worker = Proc::new do
            
                # Writes
                begin
                    chunk = io.read(@rw_len)
                    if not filter.nil?
                        chunk = filter.call(chunk)
                    end
                    @native.write(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 io.eof?
                    if not block.nil?
                        yield pos                 # returns result
                    end
                else
                    EM::next_tick { worker.call() }     # continues work
                end
                
            end
            
            worker.call()
        end
def write(data, filter = nil, &block)
            pos = 0
            
            if data.kind_of? IO
                io = data
            else
                io = StringIO::new(data)
            end
            
            worker = Proc::new do
            
                # Writes
                begin
                    chunk = io.read(@rw_len)
                    if not filter.nil?
                        chunk = filter.call(chunk)
                    end
                    @native.write(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 io.eof?
                    if not block.nil?
                        yield pos                 # returns result
                    end
                else
                    EM::next_tick { worker.call() }     # continues work
                end
                
            end
            
            worker.call()
        end
Writes data to file. Supports writing both strings or copying
 from another IO object. Returns length of written data to
 callback if filename given or current position of output
 string if IO used.

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

 @param [String, IO, StringIO] data data for write or IO object
 @param [Proc] filter filter which for preprocessing each
   written chunk
 @param [Proc] block callback called when finish and for giving
   back the length of written data
 @yield [Integer] length of really written data