add it-length-prefixed types

This commit is contained in:
Marin Petrunić 2020-02-13 22:50:28 +01:00
parent a994ae1c51
commit 6f74c18261
No known key found for this signature in database
GPG Key ID: 834D07135E110DA5

View File

@ -0,0 +1,39 @@
declare module "it-length-prefixed" {
/* eslint-disable @typescript-eslint/interface-name-prefix */
import BufferList from "bl";
import {Buffer} from "buffer"
interface LengthDecoderFunction {
(data: Buffer | BufferList): number;
bytes: number;
}
interface LengthEncoderFunction {
(value: Buffer, target: number, offset: number): number|Buffer;
bytes: number;
}
interface Encoder {
(options?: Partial<{lengthEncoder: LengthEncoderFunction}>): AsyncGenerator<BufferList, Buffer>;
single: (chunk: Buffer, options?: Partial<{lengthEncoder: LengthEncoderFunction}>) => BufferList;
MIN_POOL_SIZE: number;
DEFAULT_POOL_SIZE: number;
}
interface DecoderOptions {
lengthDecoder: LengthDecoderFunction;
maxLengthLength: number;
maxDataLength: number;
}
interface Decoder {
(options?: Partial<DecoderOptions>): AsyncGenerator<BufferList, BufferList>;
fromReader: (reader: any, options?: Partial<DecoderOptions>) => BufferList;
MAX_LENGTH_LENGTH: number;
MAX_DATA_LENGTH: number;
}
export const encode: Encoder;
export const decode: Decoder;
}