diff --git a/integration/send-files/e2e/express.spec.ts b/integration/send-files/e2e/express.spec.ts index 448296cebaf..0fb3e1efaee 100644 --- a/integration/send-files/e2e/express.spec.ts +++ b/integration/send-files/e2e/express.spec.ts @@ -42,4 +42,12 @@ describe('Express FileSend', () => { .expect(200) .expect({ value: 'Hello world' }); }); + it('should return a file from an RxJS stream', async () => { + return request(app.getHttpServer()) + .get('/file/rxjs/stream/') + .expect(200) + .expect((res) => { + expect(res.body.toString()).to.be.eq(readmeString); + }); + }); }); \ No newline at end of file diff --git a/integration/send-files/e2e/fastify.spec.ts b/integration/send-files/e2e/fastify.spec.ts index 4d3cca9065d..f6e5f2f9ce4 100644 --- a/integration/send-files/e2e/fastify.spec.ts +++ b/integration/send-files/e2e/fastify.spec.ts @@ -48,4 +48,12 @@ describe('Fastify FileSend', () => { expect(payload).to.be.eq({ value: 'Hello world' }); }); }); + it('should return a file from an RxJS stream', async () => { + return app.inject({ + method: 'GET', + url: '/file/rxjs/stream' + }).then(({ payload }) => { + expect(payload.toString()).to.be.eq(readmeString); + }); + }); }); diff --git a/integration/send-files/src/app.controller.ts b/integration/send-files/src/app.controller.ts index 39a087346fe..b12389e6757 100644 --- a/integration/send-files/src/app.controller.ts +++ b/integration/send-files/src/app.controller.ts @@ -1,4 +1,5 @@ import { Controller, Get, StreamableFile } from '@nestjs/common'; +import { Observable } from 'rxjs'; import { AppService } from './app.service'; import { NonFile } from './non-file'; @@ -20,4 +21,9 @@ export class AppController { getNonFile(): NonFile { return this.appService.getNonFile(); } + + @Get('file/rxjs/stream') + getRxJSFile(): Observable { + return this.appService.getRxJSFile(); + } } \ No newline at end of file diff --git a/integration/send-files/src/app.service.ts b/integration/send-files/src/app.service.ts index 94eade73a34..9e43e9c5ee3 100644 --- a/integration/send-files/src/app.service.ts +++ b/integration/send-files/src/app.service.ts @@ -1,6 +1,7 @@ import { Injectable, StreamableFile } from '@nestjs/common'; import { createReadStream, readFileSync } from 'fs'; import { join } from 'path'; +import { Observable, of } from 'rxjs'; import { NonFile } from './non-file'; @Injectable() @@ -18,4 +19,8 @@ export class AppService { getNonFile(): NonFile { return new NonFile('Hello world'); } + + getRxJSFile(): Observable { + return of(this.getReadStream()); + } } diff --git a/packages/common/file-stream/streamable-file.ts b/packages/common/file-stream/streamable-file.ts index b4b5a9e91c3..6f37f02c5ce 100644 --- a/packages/common/file-stream/streamable-file.ts +++ b/packages/common/file-stream/streamable-file.ts @@ -1,4 +1,3 @@ -import { buffer } from 'rxjs/operators'; import { Readable } from 'stream'; export class StreamableFile {