Korlátozott streamelés és feldolgozás
Kifejezett memória-, lemez-, idő- és párhuzamossági keretben tartja a fájlfeldolgozást megszakítással és biztonságos takarítással.
streaming-resource-limits
Nézd meg, miben segítMikor hasznos?
Akkor használd, ha feltöltés, archívum vagy médiakonverzió kis bemenet mellett is kimerítheti a workert.
Miben segít neked?
- Teljes pufferelés helyett visszanyomásos adatfolyamban kezeli a nagy fájlt.
- Korlátozza a kibontott méretet, futásidőt és workerpárhuzamosságot.
- Elkülöníti az alfolyamat paramétereit, takarítja saját ideiglenes fájlját.
Például ezt kérheted
Kezelj túlméretes archívumot biztonságosan a kibontási erőforráskeret túllépésekor. Kis, de korláton túl kicsomagolódó archívumot használj. Egyértelmű hibával álljon le, és csak a művelet saját ideiglenes fájljait takarítsa.
Részletes dokumentáció
Itt a skill eredeti útmutatóját, példáit és ellenőrzési szempontjait olvashatod az eredeti nyelven.
Összecsukás
Streaming & Resource Limits
Loading a 500 MB upload or video into an in-memory Buffer / byte[] (fs.readFile, res.arrayBuffer(), unbounded multipart buffering) crashes or starves the server as soon as three users upload concurrently. Handle file I/O and media processing with bounded streams, explicit backpressure and strict resource limits.
1. End-to-End Streaming & Backpressure
- Never buffer whole files in memory when streaming is possible:
- Pipe request/storage streams directly using backpressure-aware primitives (
stream.pipelinein Node.js, WebReadableStream.pipeTo(), Goio.Copy, Python chunked generators, PHP stream resources). - Compute cryptographic hashes (
SHA-256/MD5) and inspect initial magic bytes incrementally on the stream via transform streams rather than reading the file twice or buffering it into RAM.
- Pipe request/storage streams directly using backpressure-aware primitives (
- Direct-to-Storage Bypass:
- For files larger than a few megabytes when cloud object storage is available, prefer direct client-to-object-storage uploads (presigned URLs / multipart) so application server memory, CPU and event loops are not tied up proxying gigabytes of binary data.
- Range Requests (
HTTP 206 Partial Content):- Support
Accept-Ranges: bytesandRange: bytes=start-endon large downloads, audio/video playback and PDF previews so clients can seek and resume downloads without fetching the entire file.
- Support
2. Bounding Processing Memory, CPU, Time & Output Size
Media decoders (libvips/sharp, ImageMagick, ffmpeg, Poppler/pdfium, archive extractors) process complex binary formats that can trigger extreme memory spikes or CPU hangs:
- Pixel / Dimension Limits (Decompression Bomb Defense):
- A 400 KB PNG can have dimensions of
60000 x 60000pixels (3.6 gigapixels), which expands to 14.4 GB of uncompressed RGBA memory when decoded! - Inspect image dimensions from the header first and set hard pixel limits (e.g.,
limitInputPixelsinsharp/maxResolutionin decoders) before decoding.
- A 400 KB PNG can have dimensions of
- Execution Timeouts & Abort Signals:
- Wrap every external CLI (
ffmpeg,ffprobe,clamscan) and worker step in a hard timeout (AbortSignal.timeout(ms)/ process kill timer) that terminates hung child processes cleanly.
- Wrap every external CLI (
- Bounded Concurrency & Worker Isolation:
- Run CPU- and memory-intensive media transformations in background job queues with bounded worker concurrency (
concurrency: 2..Nmatched to container RAM/CPU), never synchronously inside the HTTP request thread.
- Run CPU- and memory-intensive media transformations in background job queues with bounded worker concurrency (
- Safe Subprocess Invocation:
- Spawn external tools (
ffmpeg,ffprobe,gs) using argument arrays (execFile/spawn(bin, args, { shell: false })) — never interpolate filenames or metadata into a shell string! - When passing paths to
ffmpegor CLI tools, prefix local relative paths (./input.mp4or absolute paths) so a filename starting with-orhttp://is never interpreted as a CLI flag or remote protocol.
- Spawn external tools (
3. Ephemeral Scratch Disk Hygiene
- When a tool requires a local file on disk (such as
ffmpegMP4 muxing or virus scanning), write to an isolated temporary directory (mkdtemp), enforce a maximum disk write quota, and guarantee deletion in atry / finallyblock even when the job throws or times out.
Csomagban lévő fájlok 1
SKILL.md
