Files
smartgulp/ts/smartgulp.classes.gulpstream.ts
T

29 lines
830 B
TypeScript

// this file contains the code to generate and handle the stream
import * as plugins from './smartgulp.plugins.js';
import { SmartFile } from '@push.rocks/smartfile';
import { Transform } from 'node:stream';
export class GulpStream {
stream = new Transform({ objectMode: true });
/**
* allows you to pipe a SmartfileArray into the stream
*/
async pipeSmartfileArray(smartfileArray: SmartFile[]): Promise<void> {
// ensure what we get is an array
if (!Array.isArray(smartfileArray)) {
throw new Error('fileArg has unknown format');
}
for (const smartfile of smartfileArray) {
const hasWritten = this.stream.push(smartfile);
if (!hasWritten) {
await plugins.smartevent.once(this.stream, 'drain');
}
}
// signal end of stream;
this.stream.push(null);
}
}