Files
frislit/server/lib/capture.js
T
fristy 650807c1fb
CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
chore: restart the repository with a clean history
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
2026-11-10 11:31:13 +03:00

37 lines
1.0 KiB
JavaScript

const { Transform } = require("node:stream");
const MAX_BODY = 64 * 1024;
class Tap extends Transform {
constructor(limit = MAX_BODY) {
super();
this.limit = limit;
this.chunks = [];
this.kept = 0;
this.total = 0;
}
_transform(chunk, _encoding, callback) {
this.total += chunk.length;
if (this.kept < this.limit) {
const room = this.limit - this.kept;
const piece = chunk.length > room ? chunk.subarray(0, room) : chunk;
this.chunks.push(piece);
this.kept += piece.length;
}
callback(null, chunk);
}
result() {
return {
body: this.chunks.length ? Buffer.concat(this.chunks, this.kept) : null,
bytes: this.total,
truncated: this.total > this.kept,
};
}
}
const headerList = headers => Object.entries(headers).flatMap(([name, value]) => [].concat(value).map(one => [name, String(one)]));
module.exports = { Tap, headerList, MAX_BODY };