A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://gist.github.com/unclexo/e7100e9ef5038a25ab43182adde3d489 below:

The Liskov Substitution Principle TypeScript code example · GitHub

Created May 23, 2023 09:39

Clone this repository at <script src="https://gist.github.com/unclexo/e7100e9ef5038a25ab43182adde3d489.js"></script>

Save unclexo/e7100e9ef5038a25ab43182adde3d489 to your computer and use it in GitHub Desktop.

The Liskov Substitution Principle TypeScript code example

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters import express, { Router, Request, Response } from 'express' import fs from 'fs'; import path from 'path'; abstract class Product { private filePath: string; private response: Response; constructor(filePath: string, response: Response) { this.filePath = filePath; this.response = response; } download() { // Set headers for downloading file this.response.setHeader('Content-Type', 'application/octet-stream'); this.response.setHeader( 'Content-Disposition', `attachment; filename="${path.basename(this.filePath)}"` ); // Read the file stream and pipe it to the response // to be download as you said so in headers const fileStream = fs.createReadStream(this.filePath); fileStream.pipe(this.response); } } class Audio extends Product {} class Video extends Product {} class Chocolate extends Product {} function download(product: Product): void { product.download(); } const router: Router = express.Router(); router.get('/download', (req: Request, res: Response) => { download(new Audio('./audio.mp3', res)); }); router.get('/lsp-violation', (req: Request, res: Response) => { download(new Chocolate('What do I do???', res)); }); export default router;

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4