Class: TransformIterator

asynciterator~TransformIterator(sourceopt, optionsopt)

An iterator that generates items based on a source iterator. This class serves as a base class for other iterators.

Constructor

new TransformIterator(sourceopt, optionsopt)

Creates a new TransformIterator.

Parameters:
Name Type Attributes Description
source module:asynciterator.AsyncIterator | Readable <optional>

The source this iterator generates items from

options object <optional>

Settings of the iterator

Properties
Name Type Attributes Default Description
maxBufferSize integer <optional>
4

The maximum number of items to keep in the buffer

autoStart boolean <optional>
true

Whether buffering starts directly after construction

optional boolean <optional>
false

If transforming is optional, the original item is pushed when its transformation yields no items

destroySource boolean <optional>
true

Whether the source should be destroyed when this transformed iterator is closed or destroyed

source module:asynciterator.AsyncIterator <optional>

The source this iterator generates items from

Extends

  • module:asynciterator.BufferedIterator

Members

source :module:asynciterator.AsyncIterator

The source this iterator generates items from.

Type:
  • module:asynciterator.AsyncIterator

Methods

(protected) _closeWhenDone()

Closes the iterator when pending items are transformed.

(protected) _loadSourceAsync()

Initializes a source that was set through a promise

_optionalTransform()

Tries to transform the item; if the transformation yields no items, pushes the original item.

_read()

Tries to read transformed items.

_readAndTransform()

Reads a transforms an item

(protected) _transform(item, done, push)

Generates items based on the item from the source. Implementers should add items through BufferedIterator#_push. The default implementation pushes the source item as-is.

Parameters:
Name Type Description
item object

The last read item from the source

done function

To be called when reading is complete

push function

A callback to push zero or more transformation results.

(protected) _validateSource(source, allowDestination)

Validates whether the given iterator can be used as a source.

Parameters:
Name Type Default Description
source object

The source to validate

allowDestination boolean false

Whether the source can already have a destination