UNPKG

2.26 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 { 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(
41 chunk: any & T,
42 cb?: Function
43 ): ReturnType<Writable['end']> extends Writable ? this : void;
44 end(
45 chunk: any & T,
46 encoding?: any,
47 cb?: Function
48 ): ReturnType<Writable['end']> extends Writable ? this : void;
49}
50
51export interface ObjectWritable<T> extends IntermediateObjectWritable<T> {
52 _write(chunk: T, encoding: string, callback: Function): void;
53 write(chunk: T, cb?: Function): boolean;
54 write(chunk: T, encoding?: any, cb?: Function): boolean;
55 setDefaultEncoding(encoding: string): this;
56 end(): ReturnType<Writable['end']> extends Writable ? this : void;
57 end(
58 chunk: T,
59 cb?: Function
60 ): ReturnType<Writable['end']> extends Writable ? this : void;
61 end(
62 chunk: T,
63 encoding?: any,
64 cb?: Function
65 ): ReturnType<Writable['end']> extends Writable ? this : void;
66}