Processes and maps files in windows/arrays of a specified size.
Install with npm:
$ npm i gulp-windowed --save
This example concatenates groups of 5 markdown files. If
src/posts contained files
post99.md then the next pipe would receive a stream containing
page0.md is the concatenation of
post4.md. The ordering is guaranteed by the use of gulp-sort.
const gulp =const sort =const windowed =const concat =gulp
Here it is used to split groups of files into different folders.
const gulp =const windowed =const rename =gulp
Here it is used to skip every other file.
const gulp =const windowed =gulp
Notice that the stream of
File objects in the callback can be returned from the callback. They are subsequently written to the resulting stream for the next pipe outside the callback. This is useful because it allows you to perform stream operations on the groups of files, while also allowing you to merge the resulting streams back together to continue performing operations.
If you'd like an array of
File objects instead of a stream then call
windowed(n, cb) -> DuplexObjectStream<File>
cb with a readable object stream (or array for
File objects each time
n are written to it. On stream end if there are any remaining
File objects because the
n threshold was not met then
cb is called with a readable object stream (or array for
window.array) containing the remaining [0,
File objects. The contents of the duplex object stream returned by the method depends on
cb (explained below).
int- A number of
Fileobjects to include per window. Must be a positive integer.
(files, i, done) -> File | Array<File> | Promise<File | Array<File> | *> | Observable<File | Array<File> | *> | ChildProcess | ReadableObjectStream<File> | undefined- A callback which either calls
doneor returns a
Fileobject, an array of
Fileobjects, or an asynchronous operation in some returnable format (see possible
cbreturn types and async-done). If an asynchronous operation is returned it will be resolved. If the result of
cb, through calling
doneor returning an asynchronous operation, is a
Fileobject or an array of
Fileobjects then they will be written to the duplex object stream returned from
ReadableObjectStream<File> | Array<File>- A readable object stream (or array for
window.array) containing up to
Fileobjects (see above from why not exactly
int- The current zero-based window number (i.e. the number of times
cbhas been called minus one).
(err, result) -> undefined- Call
done(new Error(...))for error or
done(null, result)for success when performing asynchronous operations in non-returnable format or when performing strictly synchronous operations. This method does not need to be and should not be called if a valid value of the types mentioned above is returned from
Pairs Well With
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Install dev dependencies:
$ npm i -d && npm test