* Places this write stream into an aborted state (all future writes fail) * and deletes all chunks that have already been written.
()
| 199 | * and deletes all chunks that have already been written. |
| 200 | */ |
| 201 | async abort(): Promise<void> { |
| 202 | if (this.state.streamEnd) { |
| 203 | // TODO(NODE-3485): Replace with MongoGridFSStreamClosed |
| 204 | throw new MongoAPIError('Cannot abort a stream that has already completed'); |
| 205 | } |
| 206 | |
| 207 | if (this.state.aborted) { |
| 208 | // TODO(NODE-3485): Replace with MongoGridFSStreamClosed |
| 209 | throw new MongoAPIError('Cannot call abort() on a stream twice'); |
| 210 | } |
| 211 | |
| 212 | this.state.aborted = true; |
| 213 | const remainingTimeMS = this.timeoutContext?.getRemainingTimeMSOrThrow( |
| 214 | `Upload timed out after ${this.timeoutContext?.timeoutMS}ms` |
| 215 | ); |
| 216 | |
| 217 | await this.chunks.deleteMany({ files_id: this.id }, { timeoutMS: remainingTimeMS }); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | function handleError(stream: GridFSBucketWriteStream, error: Error, callback: Callback): void { |