MCPcopy
hub / github.com/callstack/agent-device / waitForStableFile

Function waitForStableFile

src/utils/video.ts:35–64  ·  view source on GitHub ↗
(
  filePath: string,
  options: { pollMs?: number; attempts?: number } = {},
)

Source from the content-addressed store, hash-verified

33let videoValidatorExecutablePathPromise: Promise<string> | undefined;
34
35export async function waitForStableFile(
36 filePath: string,
37 options: { pollMs?: number; attempts?: number } = {},
38): Promise<void> {
39 const pollMs = options.pollMs ?? 150;
40 const attempts = options.attempts ?? 12;
41 let previousSize: number | undefined;
42 let stableCount = 0;
43
44 for (let attempt = 0; attempt < attempts; attempt += 1) {
45 let currentSize = 0;
46 try {
47 currentSize = fs.statSync(filePath).size;
48 } catch {
49 currentSize = 0;
50 }
51
52 if (currentSize > 0 && currentSize === previousSize) {
53 stableCount += 1;
54 if (stableCount >= 2) {
55 return;
56 }
57 } else {
58 stableCount = 0;
59 }
60
61 previousSize = currentSize;
62 await sleep(pollMs);
63 }
64}
65
66export async function isPlayableVideo(filePath: string): Promise<boolean> {
67 try {

Callers 1

exportProcessedVideoFunction · 0.90

Calls 1

sleepFunction · 0.90

Tested by

no test coverage detected