mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-10-13 00:01:27 +11:00
chore: update public repo
This commit is contained in:
parent
728699b3ec
commit
96ca247fcb
6 changed files with 261 additions and 133 deletions
16
utils/fs.ts
16
utils/fs.ts
|
@ -21,3 +21,19 @@ export async function directoryExists(path: string): Promise<boolean> {
|
|||
export function sanitizeFilename(filename: string) {
|
||||
return filename.replace(/[/\\?%*:|"<>]/g, '_')
|
||||
}
|
||||
|
||||
export async function writeWebStreamToFile(stream: ReadableStream<unknown>, path: string) {
|
||||
const fd = await fsp.open(path, 'w+')
|
||||
const writer = fd.createWriteStream()
|
||||
|
||||
for await (const chunk of stream as any) {
|
||||
writer.write(chunk)
|
||||
}
|
||||
|
||||
writer.end()
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
writer.on('error', reject)
|
||||
writer.on('finish', resolve)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue