# Class: AsyncFile

## vertx-js/async_file~ AsyncFile

#### new AsyncFile()

  Represents a file on the file-system which can be read from, or written to asynchronously.

  Source:
    - async_file.js, line 32

### Methods

#### close(handler)

  Close the file. The actual close happens asynchronously. The handler will be called when the close is complete, or an error occurs.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function | the handler

  Source:
    - async_file.js, line 196

#### drainHandler(handler) → {AsyncFile}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function |

  Source:
    - async_file.js, line 165

  ##### Returns:

  Type
    AsyncFile

#### endHandler(endHandler) → {AsyncFile}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `endHandler` | function |

  Source:
    - async_file.js, line 103

  ##### Returns:

  Type
    AsyncFile

#### exceptionHandler(handler) → {AsyncFile}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function |

  Source:
    - async_file.js, line 179

  ##### Returns:

  Type
    AsyncFile

#### flush(handler) → {AsyncFile}

  Same as AsyncFile#flush but the handler will be called when the flush is complete or if an error occurs

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function |

  Source:
    - async_file.js, line 250

  ##### Returns:

  Type
    AsyncFile

#### handler(handler) → {AsyncFile}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `handler` | function |

  Source:
    - async_file.js, line 59

  ##### Returns:

  Type
    AsyncFile

#### pause() → {AsyncFile}

  Source:
    - async_file.js, line 75

  ##### Returns:

  Type
    AsyncFile

#### read(buffer, offset, position, length, handler) → {AsyncFile}

  Reads `length` bytes of data from the file at position `position` in the file, asynchronously.

  The read data will be written into the specified `Buffer buffer` at position `offset`.

  If data is read past the end of the file then zero bytes will be read.

  When multiple reads are invoked on the same file there are no guarantees as to order in which those reads actually occur.

  The handler will be called when the close is complete, or if an error occurs.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `buffer` | Buffer | the buffer to read into
  `offset` | number | the offset into the buffer where the data will be read
  `position` | number | the position in the file where to start reading
  `length` | number | the number of bytes to read
  `handler` | function | the handler to call when the write is complete

  Source:
    - async_file.js, line 229

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    AsyncFile

#### resume() → {AsyncFile}

  Source:
    - async_file.js, line 89

  ##### Returns:

  Type
    AsyncFile

#### setReadBufferSize(readBufferSize) → {AsyncFile}

  Sets the buffer size that will be used to read the data from the file. Changing this value will impact how much the data will be read at a time from the file system.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `readBufferSize` | number | the buffer size

  Source:
    - async_file.js, line 305

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    AsyncFile

#### setReadPos(readPos) → {AsyncFile}

  Sets the position from which data will be read from when using the file as a ReadStream.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `readPos` | number | the position in the file

  Source:
    - async_file.js, line 274

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    AsyncFile

#### setWritePos(writePos) → {AsyncFile}

  Sets the position from which data will be written when using the file as a WriteStream.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `writePos` | number | the position in the file

  Source:
    - async_file.js, line 289

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    AsyncFile

#### setWriteQueueMaxSize(maxSize) → {AsyncFile}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `maxSize` | number |

  Source:
    - async_file.js, line 151

  ##### Returns:

  Type
    AsyncFile

#### write(buffer, position, handler) → {AsyncFile}

  Write a Buffer to the file at position `position` in the file, asynchronously.

  If `position` lies outside of the current size of the file, the file will be enlarged to encompass it.

  When multiple writes are invoked on the same file there are no guarantees as to order in which those writes actually occur

  The handler will be called when the write is complete, or if an error occurs.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `buffer` | Buffer | the buffer to write
  `position` | number | the position in the file to write it at
  `handler` | function | the handler to call when the write is complete

  Source:
    - async_file.js, line 128

  ##### Returns:

  a reference to this, so the API can be used fluently
  Type
    AsyncFile

#### writeQueueFull() → {boolean}

  This will return `true` if there are more bytes in the write queue than the value set using AsyncFile#setWriteQueueMaxSize
  Source:
    - async_file.js, line 46

  ##### Returns:

  true if write queue is full
  Type
    boolean