| 1 | // pre-compressed variants for static serving. applies to everything that is |
| 2 | // not already compressed (media containers, archives, ...). |
| 3 | export const processors: Processor[] = [ |
| 4 | { name: "gzip", fn: () => zlib.createGzip({ level: 9 }) }, |
| 5 | { name: "zstd", fn: () => zlib.createZstdCompress() }, |
| 6 | ].map(({ name, fn }) => ({ |
| 7 | name, |
| 8 | version: 1, |
| 9 | title: `compress ${name}`, |
| 10 | exclude: rules.extsPreCompressed, |
| 11 | async run({ path, mediaFile, node, signal }) { |
| 12 | await derived.produce({ |
| 13 | mediaFile, |
| 14 | node, |
| 15 | cores: 1, |
| 16 | subkey: name, |
| 17 | async producer(dir) { |
| 18 | await stream.promises.pipeline( |
| 19 | fs.createReadStream(path.toString()), |
| 20 | fn(), |
| 21 | fs.createWriteStream(dir.join(name).toString()), |
| 22 | { signal }, |
| 23 | ); |
| 24 | }, |
| 25 | }); |
| 26 | }, |
| 27 | })); |
| 28 | |
| 29 | import * as fs from "node:fs"; |
| 30 | import * as stream from "node:stream"; |
| 31 | import * as zlib from "node:zlib"; |
| 32 | |
| 33 | import * as derived from "#src/file-viewer/models/derived.ts"; |
| 34 | import * as rules from "#src/file-viewer/rules.ts"; |
| 35 | import type { Processor } from "../registry.ts"; |