Chore: async write stream & mkdirp

This commit is contained in:
SukkaW
2024-09-15 14:06:22 +08:00
parent 49787fc664
commit e7cc9e2924
7 changed files with 60 additions and 23 deletions

View File

@@ -0,0 +1,9 @@
import type { Writable } from 'node:stream';
import { once } from 'node:events';
export const asyncWriteToStream = <T>(stream: Writable, chunk: T) => {
const res = stream.write(chunk);
if (!res) {
return once(stream, 'drain'); // returns a promise only if needed
}
};