MCPcopy
hub / github.com/CapSoftware/Cap / readStreamWithLimit

Function readStreamWithLimit

apps/media-server/src/lib/media-video.ts:855–885  ·  view source on GitHub ↗
(
	stream: ReadableStream<Uint8Array>,
	maxBytes: number,
)

Source from the content-addressed store, hash-verified

853}
854
855async function readStreamWithLimit(
856 stream: ReadableStream<Uint8Array>,
857 maxBytes: number,
858): Promise<string> {
859 const reader = stream.getReader();
860 const chunks: Uint8Array[] = [];
861 let totalBytes = 0;
862
863 try {
864 while (true) {
865 const { done, value } = await reader.read();
866 if (done) break;
867 if (totalBytes < maxBytes) {
868 const remainingBytes = maxBytes - totalBytes;
869 const chunk =
870 value.length > remainingBytes
871 ? value.slice(0, remainingBytes)
872 : value;
873 chunks.push(chunk);
874 totalBytes += chunk.length;
875 }
876 }
877 } finally {
878 reader.releaseLock();
879 }
880
881 const decoder = new TextDecoder();
882 return chunks
883 .map((chunk) => decoder.decode(chunk, { stream: true }))
884 .join("");
885}
886
887async function storageResponseError(
888 prefix: string,

Callers 4

storageResponseErrorFunction · 0.70
runFfmpegCommandFunction · 0.70
probeH264LevelFunction · 0.70
generateThumbnailFunction · 0.70

Calls 1

readMethod · 0.80

Tested by

no test coverage detected