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

Method appendChunk

packages/recorder-core/src/recording-spool.ts:268–304  ·  view source on GitHub ↗
(chunk: Blob)

Source from the content-addressed store, hash-verified

266 }
267
268 appendChunk(chunk: Blob) {
269 if (this.disposed) {
270 return Promise.reject(new Error("Recording spool has been disposed"));
271 }
272
273 if (this.writeError) {
274 return Promise.reject(this.writeError);
275 }
276
277 this.pendingChunks.push(chunk);
278 this.pendingChunkBytes += chunk.size;
279 if (this.pendingChunkBytes > this.maxPendingChunkBytes) {
280 this.writeError = new RecordingSpoolBackpressureError();
281 return Promise.reject(this.writeError);
282 }
283
284 return this.enqueue(async () => {
285 const index = this.nextChunkIndex;
286 const updatedSession = {
287 ...this.session,
288 totalBytes: this.session.totalBytes + chunk.size,
289 chunkCount: this.session.chunkCount + 1,
290 updatedAt: Date.now(),
291 } satisfies RecordingSpoolSessionRecord;
292
293 await this.backend.appendChunk(updatedSession, index, chunk);
294 const persistedChunk = this.pendingChunks.shift();
295 if (persistedChunk) {
296 this.pendingChunkBytes = Math.max(
297 0,
298 this.pendingChunkBytes - persistedChunk.size,
299 );
300 }
301 this.nextChunkIndex = index + 1;
302 this.session = updatedSession;
303 });
304 }
305
306 // Heartbeat for the liveness contract above: refreshes the session's
307 // updatedAt without writing a chunk so paused recordings stay recognisably

Callers

nothing calls this directly

Calls 2

enqueueMethod · 0.95
appendChunkMethod · 0.65

Tested by

no test coverage detected