Skip to content

Commit

Permalink
Fix stream()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 13, 2019
1 parent d7886cb commit a102d21
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/stream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { callbackify } from 'util'
import { Buffer } from 'buffer'

import through from 'through2-concurrent'

Expand All @@ -16,6 +17,7 @@ export const stream = function(mapFunc, opts) {
const { maxConcurrency, result: resultOpt, ...optsA } = parseOpts({
opts,
defaultOpts,
forcedOpts,
})

return through.obj(
Expand All @@ -25,17 +27,20 @@ export const stream = function(mapFunc, opts) {
}

const defaultOpts = {
// Prevents by default because it would be done on each iteration.
// Also without `stdout|stderr: pipe`, `vinyl.execa` does not get
// `stdout|stderr|all` properties.
verbose: false,
// We use `through2-concurrent` because `through2` processes files serially
// The default is 16 which is too low
maxConcurrency: 100,
// What to do with the result, among 'save', 'overwrite' or 'stream'
result: 'save',
}

const forcedOpts = {
// Prevents by default because it would be done on each iteration.
// Also without `stdout|stderr: pipe`, `vinyl.execa` does not get
// `stdout|stderr|all` properties and `vinyl.contents` cannot be updated.
verbose: false,
}

const cExecVinyl = async function({ mapFunc, opts, resultOpt }, file) {
const input = await mapFunc(file)

Expand Down Expand Up @@ -71,7 +76,7 @@ const saveResult = async function({
const overwriteResult = async function({ file, childProcess }) {
const { all } = await childProcess
// eslint-disable-next-line no-param-reassign, fp/no-mutation
file.contents = all
file.contents = Buffer.from(all)
}

const streamResult = function({ file, childProcess }) {
Expand Down

0 comments on commit a102d21

Please sign in to comment.