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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug: Stream gets mangled after passing through FileType.fromStream #362

Closed
mbssantos opened this issue May 19, 2020 · 2 comments
Closed
Assignees
Labels

Comments

@mbssantos
Copy link

mbssantos commented May 19, 2020

Hey 馃憢

I'm doing a fairly simple file upload form with Node streams.
Was having some trouble getting the uploaded files to be read correctly after saving them and eventually noticed the stream was coming back mangled after checking the file type.

That's not much to go by so I made a repo to reproduce the issue.

Repo is https://github.com/mbssantos/file-type-issue
Should be simple to deproduce: clone it, npm i and run node index.js.

I've only checked PDF files and there seems to be different behaviour with PDF versions 1.3 and 1.4.
The 1.3 ends up empty whereas 1.4 gets the mangling I originally found.

Type checking is done correctly for both though.

Apologies if I'm doing something sily here, but I guess others might come across the same problem.

Edit:
I was running with version 14.4.0 but have now tested
v14.3.0
v14.2.0
v14.1.4
v14.1.3
v14.1.2
v14.1.1
v14.1.0

and all have the same issue.
Version 14.0.0 is also affected but kinda works - Chrome can't open it but Edge can.

Hope this helps!

@Borewit Borewit self-assigned this May 19, 2020
@Borewit
Copy link
Collaborator

Borewit commented May 19, 2020

You cannot consume a ReadStream twice @mbssantos.
In broken you essentially write everything what is not read by file-type, to file.

What should support you case is FileType.stream(readableStream). Please bear in mind the side effects that method.

@mbssantos
Copy link
Author

Didn't know that, thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants