Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shortcut for stream output #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

bschaepper
Copy link

avoid reading the merged file(s) to a buffer if the requested output format is stream

@@ -68,6 +67,11 @@ module.exports = (files, options) => new Promise((resolve, reject) => {
if (files.length === 1) {
const fileObjKeys = Object.keys(files[0])
if (fileObjKeys.length === 1 && fileObjKeys[0] === 'file') {
if (isStreamOutput()) {
const stream = fs.createReadStream(files[0].file);
resolve(output(stream));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for super late response. I've completely missed this PR.

I believe it should be return resolve here or it will still read the files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, we used my fork in the mean time ;)

You are absolutely right, missed the return there.

@@ -112,21 +116,27 @@ module.exports = (files, options) => new Promise((resolve, reject) => {
}

const childPromise = (isWindows && options.libPath !== 'pdftk')
? execFile(options.libPath, args)
? exec(`"${options.libPath}" ${args.join(' ')}`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are windows tests passing after this change? I know we had issues with this before in conjunction with files contaning spaces, ", , / etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I can't run the tests locally. But I assume it works, since all filepaths are quoted on line 104.
For me and my team it does on windows when using it productively, but then again, we don't have spaces or special chars in the paths. In any case it does not work with execFile on windows for us.

return stream;
}

return readFile(tmpFilePath).then(unlinkTempFile)
Copy link
Owner

@wubzz wubzz May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks any non-stream output as the promise will resolve undefined which is later passed to the output function.

On closer inspection I believe this is a bug in the new unlinkTempFile:

const unlinkTempFile = (buffer) => {
    new Promise((resolve) => {
      fs.unlink(tmpFilePath, () => resolve(buffer));
    })
  };

Ought to be

const unlinkTempFile = (buffer) =>
    new Promise((resolve) =>
      fs.unlink(tmpFilePath, () => resolve(buffer))
    );

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, completely forgot about this.. Yes, you are right. My teammate fixed it.

Klaus Heissler and others added 2 commits August 19, 2019 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants