Skip to content

Commit

Permalink
fix(NODE-3559): incorrect GridFS stream type (#2981)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakp committed Sep 13, 2021
1 parent 122b9f3 commit 3915ea8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/gridfs/download.ts
Expand Up @@ -73,7 +73,7 @@ export interface GridFSBucketReadStreamPrivate {
* Do not instantiate this class directly. Use `openDownloadStream()` instead.
* @public
*/
export class GridFSBucketReadStream extends Readable {
export class GridFSBucketReadStream extends Readable implements NodeJS.ReadableStream {
/** @internal */
s: GridFSBucketReadStreamPrivate;

Expand Down
18 changes: 11 additions & 7 deletions src/gridfs/upload.ts
Expand Up @@ -37,7 +37,7 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
* Do not instantiate this class directly. Use `openUploadStream()` instead.
* @public
*/
export class GridFSBucketWriteStream extends Writable {
export class GridFSBucketWriteStream extends Writable implements NodeJS.WritableStream {
bucket: GridFSBucket;
chunks: Collection<GridFSChunk>;
filename: string;
Expand Down Expand Up @@ -118,12 +118,16 @@ export class GridFSBucketWriteStream extends Writable {
* @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
* @returns False if this write required flushing a chunk to MongoDB. True otherwise.
*/
write(chunk: Buffer): boolean;
write(chunk: Buffer, callback: Callback<void>): boolean;
write(chunk: Buffer, encoding: BufferEncoding | undefined): boolean;
write(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
write(chunk: Buffer | string): boolean;
write(chunk: Buffer | string, callback: Callback<void>): boolean;
write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
write(
chunk: Buffer,
chunk: Buffer | string,
encoding: BufferEncoding | undefined,
callback: Callback<void>
): boolean;
write(
chunk: Buffer | string,
encodingOrCallback?: Callback<void> | BufferEncoding,
callback?: Callback<void>
): boolean {
Expand Down Expand Up @@ -417,7 +421,7 @@ function createFilesDoc(

function doWrite(
stream: GridFSBucketWriteStream,
chunk: Buffer,
chunk: Buffer | string,
encoding?: BufferEncoding,
callback?: Callback<void>
): boolean {
Expand Down
13 changes: 13 additions & 0 deletions test/types/gridfs_types.test-d.ts
@@ -0,0 +1,13 @@
import { Readable } from 'stream';
import { expectType } from 'tsd';
import type { GridFSBucket, GridFSBucketWriteStream } from '../../src';

(function test(bucket: GridFSBucket) {
const readable = new Readable();

const uploadStream = bucket.openUploadStream('test');
expectType<GridFSBucketWriteStream>(uploadStream);

// should be pipeable as a WriteStream
readable.pipe(uploadStream);
})({} as GridFSBucket);

0 comments on commit 3915ea8

Please sign in to comment.