Class: Encoder
@divine/uri.Encoder
The base class for all encoder subclasses. Encoders can be constructed manually, but usually aren't. Instead, this class provides the static methods encode and decode.
Encoders transform byte streams and are used, among other things, to handle the content-encoding
,
content-transfer-encoding
and transfer-encoding
headers in MIME and HTTP.
Below is a list of all known encoders:
Encoding | Encoder class |
---|---|
7bit | IdentityEncoder |
8bit | IdentityEncoder |
base64 | Base64Encoder |
base64url | Base64Encoder |
binary | IdentityEncoder |
br | ZlibEncoder |
deflate | ZlibEncoder |
gzip | ZlibEncoder |
identity | IdentityEncoder |
quoted-printable | QuotedPrintableEncoder |
x-gzip | ZlibEncoder |
Hierarchy
Constructors
constructor
• Protected
new Encoder(type
)
Constructs a new Encoder instance.
Parameters
Name | Type | Description |
---|---|---|
type | string | The encoding format this encoder object was instanciated for. |
Defined in
Properties
type
• Readonly
type: string
The encoding format this encoder object was instanciated for.
Defined in
Methods
decode
▸ Abstract
decode(stream
): AsyncIterable
<Buffer
>
Decodes the provided byte stream into an new byte stream.
This method must be implemented by the actual subclass.
Throws
EncoderError On decoding errors.
Parameters
Name | Type | Description |
---|---|---|
stream | AsyncIterable <Buffer > | The stream to decode. |
Returns
AsyncIterable
<Buffer
>
The decoded stream.
Defined in
encode
▸ Abstract
encode(stream
): AsyncIterable
<Buffer
>
Encodes the provided byte stream into an new byte stream.
This method must be implemented by the actual subclass.
Throws
EncoderError On encoding errors.
Parameters
Name | Type | Description |
---|---|---|
stream | AsyncIterable <Buffer > | The stream to encode. |
Returns
AsyncIterable
<Buffer
>
The encoded stream.
Defined in
decode
▸ Static
decode(stream
, types
): Readable
& AsyncIterable
<Buffer
>
Decodes the provided stream using one or more encoders.
Throws
EncoderError On decoding errors or if the encoding format is not recognized.
Parameters
Name | Type | Description |
---|---|---|
stream | string | Buffer | AsyncIterable <Buffer > | The data to encode. If a string, it will first converted to UTF-8. |
types | string | string [] | An encoding format or an ordered list of encoding formats to apply (in reverse!) to the stream. A list may either be a comma-separated string or an array of strings. |
Returns
Readable
& AsyncIterable
<Buffer
>
An encoded byte stream.
Defined in
encode
▸ Static
encode(stream
, types
): Readable
& AsyncIterable
<Buffer
>
Encodes the provided stream using one or more encoders.
Throws
EncoderError On encoding errors or if the encoding format is not recognized.
Parameters
Name | Type | Description |
---|---|---|
stream | string | Buffer | AsyncIterable <Buffer > | The data to encode. If a string, it will first converted to UTF-8. |
types | string | string [] | An encoding format or an ordered list of encoding formats to apply to the stream. A list may either be a comma-separated string or an array of strings. |
Returns
Readable
& AsyncIterable
<Buffer
>
An encoded byte stream.
Defined in
register
▸ Static
register(type
, encoder
): typeof Encoder
Registers a new encoder. All subclasses must register their encoding type support with this method.
Parameters
Name | Type | Description |
---|---|---|
type | string | The encoding format the encoder can handle. |
encoder | typeof Encoder | The Encoder subclass to register. |
Returns
typeof Encoder
The Encoder base class (for method chaining).