# Class: PacketList

## PacketList()

This class represents a list of openpgp packets. Take care when iterating over it - the packets themselves are stored as numerical indices.

## Constructor

#### new PacketList()

Source:
  - packet/packetlist.js, line 41

### Extends

- Array

### Methods

#### (async, static) fromBinary(bytes, allowedPackets, configopt) → {PacketList}

Parses the given binary data and returns a list of packets. Equivalent to calling `read` on an empty PacketList instance.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`bytes` | Uint8Array | ReadableStream.<Uint8Array> |  | binary data to parse
`allowedPackets` | Object |  | mapping where keys are allowed packet tags, pointing to their Packet class
`config` | Object | <optional> | full configuration, defaults to openpgp.config

Source:
  - packet/packetlist.js, line 52

##### Throws:

on parsing errors

##### Returns:

parsed list of packets

Type
  PacketList

#### filterByTag(…tags) → {PacketList}

Creates a new PacketList with all packets matching the given tag(s)

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`tags` | module:enums.packet | <repeatable> | packet tags to look for

Source:
  - packet/packetlist.js, line 179

##### Returns:

Type
  PacketList

#### findPacket(tag) → {Packet|undefined}

Traverses packet list and returns first packet with matching tag

##### Parameters:

Name | Type | Description
--- | --- | ---
`tag` | module:enums.packet | The packet tag

Source:
  - packet/packetlist.js, line 198

##### Returns:

Type
  Packet | undefined

#### indexOfTag(…tags) → {Array.<Integer>}

Find indices of packets with the given tag(s)

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`tags` | module:enums.packet | <repeatable> | packet tags to look for

Source:
  - packet/packetlist.js, line 207

##### Returns:

packet indices

Type
  Array.<Integer>

#### (async) read(bytes, allowedPackets, configopt)

Reads a stream of binary data and interprets it as a list of packets.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`bytes` | Uint8Array | ReadableStream.<Uint8Array> |  | binary data to parse
`allowedPackets` | Object |  | mapping where keys are allowed packet tags, pointing to their Packet class
`config` | Object | <optional> | full configuration, defaults to openpgp.config

Source:
  - packet/packetlist.js, line 66

##### Throws:

on parsing errors

#### write() → {Uint8Array}

Creates a binary representation of openpgp objects contained within the class instance.

Source:
  - packet/packetlist.js, line 135

##### Returns:

A Uint8Array containing valid openpgp packets.

Type
  Uint8Array