Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 49 additions & 21 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,50 @@ async function compress(params) {
} = params;

const handlers = [
filter(item => item.dirent.isFile()),
filter(item => extWhiteList.includes(path.extname(item.direntPath))),
fileSize && map(async item => {
const stat = await fsp.stat(item.direntPath);
return {
...item,
size: stat.size
}
}),
fileSize && filter(item => item.size > fileSize),
switchMap(function* (item) {
for (const format of formats) {
yield {
{
condition: true,
operator: 'filter',
handler: item => item.dirent.isFile()
},
{
condition: true,
operator: 'filter',
handler: item => extWhiteList.includes(path.extname(item.direntPath))
},
{
condition: fileSize,
operator: 'map',
handler: async item => {
const stat = await fsp.stat(item.direntPath);
return {
...item,
format
size: stat.size
}
}
},
{
condition: fileSize,
operator: 'filter',
handler: item => item.size > fileSize
},
{
condition: true,
operator: 'flatMap',
handler: function* (item) {
for (const format of formats) {
yield {
...item,
format
}
}
}
}),
parallel({
concurrency,
},
{
condition: true,
operator: 'forEach',
options: {
concurrency
},
handler: async (item) => {
const fromPath = item.direntPath;
const relativePath = path.relative(from, fromPath);
Expand All @@ -74,11 +98,15 @@ async function compress(params) {

return createCompressStream({ fromPath, toPath, format: item.format });
}
}),
].filter(Boolean);
}
].filter(handlerData => handlerData.condition);

const iterable = pipe(...handlers)(walk(from));
return subscribe(iterable, x => x);
return handlers.reduce(
(currentStream, handlerData) => {
return currentStream[handlerData.operator](handlerData.handler, handlerData.options)
},
stream.Readable.from(walk(from))
)
}


Expand Down