(
filePath: string,
options: { pollMs?: number; attempts?: number } = {},
)
| 33 | let videoValidatorExecutablePathPromise: Promise<string> | undefined; |
| 34 | |
| 35 | export 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 | |
| 66 | export async function isPlayableVideo(filePath: string): Promise<boolean> { |
| 67 | try { |
no test coverage detected