Skip to content

Commit

Permalink
Fix opts.encoding in stream mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 17, 2019
1 parent 01fcfc4 commit a17ea01
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/stream/result.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Buffer } from 'buffer'

import { isValidInput } from '../input.js'
import { execCommand, streamCommand } from '../exec.js'
import { streamError } from '../error.js'
Expand Down Expand Up @@ -56,7 +58,10 @@ const streamResult = function({ file, input, opts, opts: { from } }) {
}

const bufferResult = async function({ file, input, opts, opts: { from } }) {
const { [from]: buffer } = await execCommand(input, opts)
const { [from]: output } = await execCommand(input, opts)
// Stream output can be either string or buffer depending on `opts.encoding`
// However `file.contents` cannot be a string.
const buffer = Buffer.isBuffer(output) ? output : Buffer.from(output)
// eslint-disable-next-line no-param-reassign, fp/no-mutation
file.contents = buffer
}

0 comments on commit a17ea01

Please sign in to comment.