Class: Vertx::AsyncFile

Inherits:
Object
  • Object
show all
Includes:
ReadStream, WriteStream
Defined in:
src/main/api_shim/core/file_system.rb

Overview

Represents a file on the file-system which can be read from, or written to asynchronously. The class also includes ReadStream and WriteStream - this allows the data to be pumped to and from other streams, e.g. an HttpClientRequest instance, using the Pump class

Author:

Instance Method Summary (collapse)

Methods included from ReadStream

#data_handler, #end_handler, #exception_handler, #pause, #resume

Methods included from WriteStream

#drain_handler, #exception_handler, #write, #write_queue_full?, #write_queue_max_size, #write_queue_max_size=

Instance Method Details

- (Object) close(&block)

Close the file, asynchronously.


111
112
113
# File 'src/main/api_shim/core/file_system.rb', line 111

def close(&block)
  @j_del.close(ARWrappedHandler.new(block))
end

- (Object) flush

Flush any writes made to this file to underlying persistent storage, asynchronously. If the file was opened with flush set to true then calling this method will have no effect.

Parameters:

  • hndlr (Block)
    a block representing the handler which is called on completion.


141
142
143
144
# File 'src/main/api_shim/core/file_system.rb', line 141

def flush
  Future.new(@j_del.flush)
  self
end

- (Object) read_at_pos(buffer, offset, position, length, &block)

Reads some data from a file into a buffer, asynchronously. When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.

Parameters:

  • buffer (Buffer)
    The buffer into which the data which is read is written.
  • offset (FixNum)
    The position in the buffer where to start writing the data.
  • position (FixNum)
    The position in the file where to read the data.
  • length (FixNum)
    The number of bytes to read.


133
134
135
136
# File 'src/main/api_shim/core/file_system.rb', line 133

def read_at_pos(buffer, offset, position, length, &block)
  @j_del.read(buffer._to_java_buffer, offset, position, length, ARWrappedHandler.new(block) { |j_buff| Buffer.new(j_buff) })
  self
end

- (Object) write_at_pos(buffer, position, &block)

Write a Buffer to the file, asynchronously. When multiple writes are invoked on the same file there are no guarantees as to order in which those writes actually occur. starts with zero at the beginning of the file.

Parameters:

  • buffer (Buffer)
    The buffer to write
  • position (FixNum)
    The position in the file where to write the buffer. Position is measured in bytes and


121
122
123
124
# File 'src/main/api_shim/core/file_system.rb', line 121

def write_at_pos(buffer, position, &block)
  @j_del.write(buffer._to_java_buffer, position, ARWrappedHandler.new(block))
  self
end