mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
check for stream truncation in saveToTempFile
This commit is contained in:
parent
e75e4f11a2
commit
7bfe16cbb0
1 changed files with 9 additions and 2 deletions
|
@ -30,13 +30,20 @@ export function createTempDir(): Promise<[string, () => void]> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function saveToTempFile(stream: NodeJS.ReadableStream): Promise<[string, () => void]> {
|
||||
export async function saveToTempFile(stream: NodeJS.ReadableStream & { truncated?: boolean }): Promise<[string, () => void]> {
|
||||
const [filepath, cleanup] = await createTemp();
|
||||
|
||||
try {
|
||||
await pipeline(stream, fs.createWriteStream(filepath));
|
||||
return [filepath, cleanup];
|
||||
} catch (e) {
|
||||
cleanup();
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (stream.truncated) {
|
||||
cleanup();
|
||||
throw new Error('Read failed: input stream truncated');
|
||||
}
|
||||
|
||||
return [filepath, cleanup];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue