UNPKG

rjweb-server

Version:

Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS

35 lines (34 loc) 785 B
import { Duplex, PassThrough } from "stream"; import size from "./size"; import zlib from "zlib"; class PassThrough64K extends Duplex { constructor() { super({ read() { }, write(chunk) { let chunkCount = Math.ceil(chunk.byteLength / size(64).kb()), index = 0; while (chunkCount) { this.push(chunk.slice(index, index + size(64).kb())); index += size(64).kb(); chunkCount--; } } }); } } function handleCompressType(type) { switch (type) { case "gzip": return zlib.createGzip(); case "br": return zlib.createBrotliCompress(); case "deflate": return zlib.createDeflate(); default: return new PassThrough(); } } export { handleCompressType as default };