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

Allow input to be a Stream. #17

Closed
wants to merge 6 commits into from

Conversation

CodeMan99
Copy link

From conversation in issue #16.

The idea is that the first four bytes are read, then check file type. If not a zip, stop reading and return empty array. If it is a zip, buffer the stream and unzip as per normal.

index.js Outdated
const type = fileType(input);

return type && type.ext === 'zip' ? processZip(input) : Promise.resolve([]);
} else if (isStream(input)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Don't need else if here since we're returning inside the previous if statement.

Copy link
Author

Choose a reason for hiding this comment

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

True, personally think that else if says "or" better, but I'll change it.

index.js Outdated
});

return getStream.buffer(input.pipe(firstChunkIsZip)).then(processZip, error => {
if (error === notAZipError) {
Copy link
Owner

Choose a reason for hiding this comment

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

error => err

index.js Outdated
}

return pify(yauzl.fromBuffer)(buf, {lazyEntries: true}).then(extractFile);
return Promise.reject(new TypeError(`Expected a Buffer or Stream, got ${typeof input}`));
Copy link
Owner

Choose a reason for hiding this comment

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

Don't move this to the bottom. I want to handle exceptions as early as possible.

Copy link
Author

Choose a reason for hiding this comment

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

How is it different? Moving it to the top requires if (!isStream(input) && !Buffer.isBuffer(input)) before it. Those two expressions (besides negation) are already directly in front of this line.

Copy link
Author

Choose a reason for hiding this comment

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

@kevva Still eagerly awaiting your response.

Copy link
Author

Choose a reason for hiding this comment

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

Implemented this suggestion despite not really understanding the reasoning.

const stream = fs.createReadStream(__filename);
const files = await m()(stream);

t.is(files.length, 0);
Copy link
Author

Choose a reason for hiding this comment

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

Should probably check the readable state of the stream here, do you know what is appropriate? I am thinking stream._readableState.flowing === false and stream._readableState.ended === false.

Copy link
Author

Choose a reason for hiding this comment

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

implemented as described.

@CodeMan99
Copy link
Author

@kevva did you go on vacation? Would love to have some guidance on this if you are available.

@CodeMan99
Copy link
Author

@kevva Would love to get this PR ready for merge while the information is still fresh in my mind.

Also, it might be worth separating the "streaming file-type" part since something similar will likely need done for the decompress module.

@CodeMan99
Copy link
Author

Closing because questions have gone unanswered.

@CodeMan99 CodeMan99 closed this Sep 3, 2019
@kevva
Copy link
Owner

kevva commented Sep 6, 2019

@CodeMan99, I don't see the point in allowing a stream as input if we're going to buffer it anyway. That misses the whole point of streaming. Unless yauzl start supporting streams, or if there is a alternative module that supports it, I'm not going merge this.

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