# Class: WriteStream

## vertx-js/write_stream~ WriteStream

#### new WriteStream()

Represents a stream of data that can be written to.

Source:
  - vertx-js/write_stream.js, line 31

### Methods

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

Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump for an example of this being used.

The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to `maxSize / 2`.

##### Parameters:

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

Source:
  - vertx-js/write_stream.js, line 132

##### Returns:

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

Type
  WriteStream

#### end(t)

Same as WriteStream#end but writes some data to the stream before ending.

##### Parameters:

Name | Type | Description
--- | --- | ---
`t` | Object |

Source:
  - vertx-js/write_stream.js, line 77

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

Set an exception handler on the write stream.

##### Parameters:

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

Source:
  - vertx-js/write_stream.js, line 44

##### Returns:

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

Type
  WriteStream

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

Set the maximum size of the write queue to `maxSize`. You will still be able to write to the stream even if there is more than `maxSize` items in the write queue. This is used as an indicator by classes such as `Pump` to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, the number of Message for a MessageProducer, etc...

##### Parameters:

Name | Type | Description
--- | --- | ---
`maxSize` | number | the max size of the write stream

Source:
  - vertx-js/write_stream.js, line 99

##### Returns:

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

Type
  WriteStream

#### write(data) → {WriteStream}

Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the WriteStream#writeQueueFull method before writing. This is done automatically if using a Pump.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | the data to write

Source:
  - vertx-js/write_stream.js, line 63

##### Returns:

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

Type
  WriteStream

#### writeQueueFull() → {boolean}

This will return `true` if there are more bytes in the write queue than the value set using WriteStream#setWriteQueueMaxSize

Source:
  - vertx-js/write_stream.js, line 114

##### Returns:

true if write queue is full

Type
  boolean