UNPKG

2.21 kBPlain TextView Raw
1/*
2 * Copyright 2019 gRPC authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18import { Duplex, Readable, Writable } from 'stream';
19import { EmitterAugmentation1 } from './events';
20
21/* eslint-disable @typescript-eslint/no-explicit-any */
22
23export type WriteCallback = (error: Error | null | undefined) => void;
24
25export interface IntermediateObjectReadable<T> extends Readable {
26 read(size?: number): any & T;
27}
28
29export type ObjectReadable<T> = {
30 read(size?: number): T;
31} & EmitterAugmentation1<'data', T> &
32 IntermediateObjectReadable<T>;
33
34export interface IntermediateObjectWritable<T> extends Writable {
35 _write(chunk: any & T, encoding: string, callback: Function): void;
36 write(chunk: any & T, cb?: WriteCallback): boolean;
37 write(chunk: any & T, encoding?: any, cb?: WriteCallback): boolean;
38 setDefaultEncoding(encoding: string): this;
39 end(): ReturnType<Writable['end']> extends Writable ? this : void;
40 end(chunk: any & T, cb?: Function): ReturnType<Writable['end']> extends Writable ? this : void;
41 end(chunk: any & T, encoding?: any, cb?: Function): ReturnType<Writable['end']> extends Writable ? this : void;
42}
43
44export interface ObjectWritable<T> extends IntermediateObjectWritable<T> {
45 _write(chunk: T, encoding: string, callback: Function): void;
46 write(chunk: T, cb?: Function): boolean;
47 write(chunk: T, encoding?: any, cb?: Function): boolean;
48 setDefaultEncoding(encoding: string): this;
49 end(): ReturnType<Writable['end']> extends Writable ? this : void;
50 end(chunk: T, cb?: Function): ReturnType<Writable['end']> extends Writable ? this : void;
51 end(chunk: T, encoding?: any, cb?: Function): ReturnType<Writable['end']> extends Writable ? this : void;
52}