object-stream.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. import { Readable, Writable } from 'stream';
  18. import { EmitterAugmentation1 } from './events';
  19. /* eslint-disable @typescript-eslint/no-explicit-any */
  20. export type WriteCallback = (error: Error | null | undefined) => void;
  21. export interface IntermediateObjectReadable<T> extends Readable {
  22. read(size?: number): any & T;
  23. }
  24. export type ObjectReadable<T> = {
  25. read(size?: number): T;
  26. } & EmitterAugmentation1<'data', T> &
  27. IntermediateObjectReadable<T>;
  28. export interface IntermediateObjectWritable<T> extends Writable {
  29. _write(chunk: any & T, encoding: string, callback: Function): void;
  30. write(chunk: any & T, cb?: WriteCallback): boolean;
  31. write(chunk: any & T, encoding?: any, cb?: WriteCallback): boolean;
  32. setDefaultEncoding(encoding: string): this;
  33. end(): ReturnType<Writable['end']> extends Writable ? this : void;
  34. end(
  35. chunk: any & T,
  36. cb?: Function
  37. ): ReturnType<Writable['end']> extends Writable ? this : void;
  38. end(
  39. chunk: any & T,
  40. encoding?: any,
  41. cb?: Function
  42. ): ReturnType<Writable['end']> extends Writable ? this : void;
  43. }
  44. export 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(
  51. chunk: T,
  52. cb?: Function
  53. ): ReturnType<Writable['end']> extends Writable ? this : void;
  54. end(
  55. chunk: T,
  56. encoding?: any,
  57. cb?: Function
  58. ): ReturnType<Writable['end']> extends Writable ? this : void;
  59. }