mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[@types/node] add destroyed property for Readable and Writable (#38237)
* [@types/node] add `destroyed` property for Readable and Writable 1. https://nodejs.org/dist/latest-v12.x/docs/api/stream.html#stream_readable_destroyed 2. https://nodejs.org/dist/latest-v12.x/docs/api/stream.html#stream_writable_destroyed * [@types/node] add test for readable.destroyed/writable.destroyed 1. Property 'destroyed' is missing in type 'WriteStream' but required in type 'Writable' 2. check `destroyed` * fixed: replace Readable with ReadableStream
This commit is contained in:
parent
b3f478f123
commit
3889492dec
4
types/derhuerst__cli-on-key/index.d.ts
vendored
4
types/derhuerst__cli-on-key/index.d.ts
vendored
@ -5,8 +5,6 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import stream = require("stream");
|
||||
|
||||
declare namespace listen {
|
||||
interface Key {
|
||||
name?: string;
|
||||
@ -23,7 +21,7 @@ declare namespace listen {
|
||||
}
|
||||
|
||||
declare function listen(
|
||||
stream: stream.Readable,
|
||||
stream: NodeJS.ReadStream,
|
||||
callback: listen.Callback
|
||||
): listen.OffKeyPress;
|
||||
|
||||
|
||||
2
types/node/stream.d.ts
vendored
2
types/node/stream.d.ts
vendored
@ -26,6 +26,7 @@ declare module "stream" {
|
||||
readable: boolean;
|
||||
readonly readableHighWaterMark: number;
|
||||
readonly readableLength: number;
|
||||
destroyed: boolean;
|
||||
constructor(opts?: ReadableOptions);
|
||||
_read(size: number): void;
|
||||
read(size?: number): any;
|
||||
@ -119,6 +120,7 @@ declare module "stream" {
|
||||
readonly writableFinished: boolean;
|
||||
readonly writableHighWaterMark: number;
|
||||
readonly writableLength: number;
|
||||
destroyed: boolean;
|
||||
constructor(opts?: WritableOptions);
|
||||
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
||||
_writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
||||
|
||||
@ -32,10 +32,21 @@ import { Readable, Writable } from 'stream';
|
||||
const a: NodeJS.TypedArray = new Buffer(123);
|
||||
|
||||
{
|
||||
const stdin: Readable = process.stdin;
|
||||
let writableFinished: boolean;
|
||||
const stdout: Writable = process.stdout;
|
||||
writableFinished = process.stdout.writableFinished;
|
||||
const stderr: Writable = process.stderr;
|
||||
writableFinished = process.stderr.writableFinished;
|
||||
const readable: Readable = new Readable({
|
||||
read() {
|
||||
this.push('hello');
|
||||
this.push('world');
|
||||
this.push(null);
|
||||
},
|
||||
});
|
||||
readable.destroyed;
|
||||
const writable: Writable = new Writable({
|
||||
write(chunk, _, cb) {
|
||||
cb();
|
||||
},
|
||||
});
|
||||
readable.pipe(writable);
|
||||
writableFinished = writable.writableFinished;
|
||||
writable.destroyed;
|
||||
}
|
||||
|
||||
7
types/yazl/index.d.ts
vendored
7
types/yazl/index.d.ts
vendored
@ -7,7 +7,6 @@
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Readable } from 'stream';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
export interface Options {
|
||||
@ -37,10 +36,10 @@ export interface DosDateTime {
|
||||
|
||||
export class ZipFile {
|
||||
addFile(realPath: string, metadataPath: string, options?: Partial<Options>): void;
|
||||
outputStream: Readable;
|
||||
addReadStream(input: Readable, metadataPath: string, options?: Partial<ReadStreamOptions>): void;
|
||||
outputStream: NodeJS.ReadableStream;
|
||||
addReadStream(input: NodeJS.ReadableStream, metadataPath: string, options?: Partial<ReadStreamOptions>): void;
|
||||
addBuffer(buffer: Buffer, metadataPath: string, options?: Partial<Options>): void;
|
||||
end(optoins?: EndOptions, finalSizeCallback?: () => void): void;
|
||||
end(options?: EndOptions, finalSizeCallback?: () => void): void;
|
||||
|
||||
addEmptyDirectory(metadataPath: string, options?: Partial<DirectoryOptions>): void;
|
||||
dateToDosDateTime(jsDate: Date): DosDateTime;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { ZipFile } from "yazl";
|
||||
import { Readable } from "stream";
|
||||
import fs = require('fs');
|
||||
|
||||
const zipfile = new ZipFile();
|
||||
@ -7,7 +6,7 @@ zipfile.addFile("file1.txt", "file1.txt");
|
||||
// (add only files, not directories)
|
||||
zipfile.addFile("path/to/file.txt", "path/in/zipfile.txt");
|
||||
// pipe() can be called any time after the constructor
|
||||
// $ExpectType Readable
|
||||
// $ExpectType ReadableStream
|
||||
zipfile.outputStream;
|
||||
zipfile.outputStream.pipe(fs.createWriteStream("output.zip")).on("close", () => {
|
||||
console.log("done");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user