Skip to content

Commit 7bb9e37

Browse files
authored
fix(gridfs): make GridFSBucketWriteStream.prototype.end() return this for compat with @types/[email protected] (#3088)
1 parent 54f2352 commit 7bb9e37

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/gridfs/upload.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,21 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
172172
* @param encoding - Optional encoding for the buffer
173173
* @param callback - Function to call when all files and chunks have been persisted to MongoDB
174174
*/
175-
end(): void;
176-
end(chunk: Buffer): void;
177-
end(callback: Callback<GridFSFile | void>): void;
178-
end(chunk: Buffer, callback: Callback<GridFSFile | void>): void;
179-
end(chunk: Buffer, encoding: BufferEncoding): void;
175+
end(): this;
176+
end(chunk: Buffer): this;
177+
end(callback: Callback<GridFSFile | void>): this;
178+
end(chunk: Buffer, callback: Callback<GridFSFile | void>): this;
179+
end(chunk: Buffer, encoding: BufferEncoding): this;
180180
end(
181181
chunk: Buffer,
182182
encoding: BufferEncoding | undefined,
183183
callback: Callback<GridFSFile | void>
184-
): void;
184+
): this;
185185
end(
186186
chunkOrCallback?: Buffer | Callback<GridFSFile | void>,
187187
encodingOrCallback?: BufferEncoding | Callback<GridFSFile | void>,
188188
callback?: Callback<GridFSFile | void>
189-
): void {
189+
): this {
190190
const chunk = typeof chunkOrCallback === 'function' ? undefined : chunkOrCallback;
191191
const encoding = typeof encodingOrCallback === 'function' ? undefined : encodingOrCallback;
192192
callback =
@@ -196,7 +196,7 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
196196
? encodingOrCallback
197197
: callback;
198198

199-
if (checkAborted(this, callback)) return;
199+
if (checkAborted(this, callback)) return this;
200200

201201
this.state.streamEnd = true;
202202

@@ -208,12 +208,14 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
208208

209209
if (!chunk) {
210210
waitForIndexes(this, () => !!writeRemnant(this));
211-
return;
211+
return this;
212212
}
213213

214214
this.write(chunk, encoding, () => {
215215
writeRemnant(this);
216216
});
217+
218+
return this;
217219
}
218220
}
219221

0 commit comments

Comments
 (0)