diff --git a/package-lock.json b/package-lock.json index 5f631cc..088c41e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8802,4 +8802,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/base_http_controller.ts b/src/base_http_controller.ts index cc58fca..f3f36ac 100644 --- a/src/base_http_controller.ts +++ b/src/base_http_controller.ts @@ -68,11 +68,11 @@ export class BaseHttpController { ): JsonResult { return new JsonResult(content, statusCode); } - + protected stream( - readableStream: Readable, - contentType: string, - statusCode: number = StatusCodes.OK + readableStream: Readable, + contentType: string, + statusCode: number = StatusCodes.OK ): StreamResult { return new StreamResult(readableStream, contentType, statusCode); } diff --git a/src/results/StreamResult.ts b/src/results/StreamResult.ts index 6650928..c89566e 100644 --- a/src/results/StreamResult.ts +++ b/src/results/StreamResult.ts @@ -5,19 +5,18 @@ import { StreamContent } from '../content/streamContent'; export class StreamResult implements IHttpActionResult { - constructor( - public readableStream: Readable, - public contentType: string, - public readonly statusCode: number, - ) { - } + constructor( + public readableStream: Readable, + public contentType: string, + public readonly statusCode: number + ) { } - public async executeAsync(): Promise { - const response = new HttpResponseMessage(this.statusCode); - response.content = new StreamContent( - this.readableStream, - this.contentType, - ); - return Promise.resolve(response); - } + public async executeAsync(): Promise { + const response = new HttpResponseMessage(this.statusCode); + response.content = new StreamContent( + this.readableStream, + this.contentType, + ); + return Promise.resolve(response); + } } diff --git a/test/content/streamContent.test.ts b/test/content/streamContent.test.ts index 9cc50c6..4ed6fac 100644 --- a/test/content/streamContent.test.ts +++ b/test/content/streamContent.test.ts @@ -2,44 +2,44 @@ import { Readable, Writable } from 'stream'; import { StreamContent } from '../../src/content/streamContent'; describe('StreamContent', () => { - it('should have text/plain as the set media type', () => { - const stream = new Readable(); + it('should have text/plain as the set media type', () => { + const stream = new Readable(); - const content = new StreamContent(stream, 'text/plain'); + const content = new StreamContent(stream, 'text/plain'); - expect(content.headers['content-type']).toEqual('text/plain'); - }); + expect(content.headers['content-type']).toEqual('text/plain'); + }); - it('should be able to pipe stream which was given to it', done => { - const stream = new Readable({ - read() { - this.push(Buffer.from('test')); - this.push(null); - }, - }); + it('should be able to pipe stream which was given to it', done => { + const stream = new Readable({ + read() { + this.push(Buffer.from('test')); + this.push(null); + }, + }); - const content = new StreamContent(stream, 'text/plain'); + const content = new StreamContent(stream, 'text/plain'); - void content.readAsync().then((readable: Readable) => { - const chunks: Array = []; + void content.readAsync().then((readable: Readable) => { + const chunks: Array = []; - let buffer: Buffer | null = null; + let buffer: Buffer | null = null; - readable.on('end', () => { - buffer = Buffer.concat(chunks); + readable.on('end', () => { + buffer = Buffer.concat(chunks); - expect(buffer.toString()).toEqual('test'); + expect(buffer.toString()).toEqual('test'); - done(); - }); + done(); + }); - const writableStream = new Writable({ - write(chunk) { - chunks.push(chunk as Buffer); - }, - }); + const writableStream = new Writable({ + write(chunk) { + chunks.push(chunk as Buffer); + }, + }); - readable.pipe(writableStream); - }); + readable.pipe(writableStream); }); + }); }); diff --git a/test/features/decorator_middleware.test.ts b/test/features/decorator_middleware.test.ts index 885f10e..d0121f7 100644 --- a/test/features/decorator_middleware.test.ts +++ b/test/features/decorator_middleware.test.ts @@ -2,15 +2,8 @@ import * as express from 'express'; import supertest from 'supertest'; import { Container } from 'inversify'; import { METADATA_KEY } from '../../src/constants'; -import { - BaseMiddleware, - ControllerMethodMetadata, - InversifyExpressServer, - ControllerMetadata, -} from '../../src/index'; -import { - controller, httpGet, httpMethod, httpPut, withMiddleware, -} from '../../src/decorators'; +import { BaseMiddleware, ControllerMethodMetadata, InversifyExpressServer, ControllerMetadata } from '../../src/index'; +import { controller, httpGet, httpMethod, httpPut, withMiddleware } from '../../src/decorators'; import { cleanUpMetadata } from '../../src/utils'; import assert from 'assert';