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

Cannot download PNG file with iValue.download() method #186

Open
ncalaway opened this issue Dec 3, 2021 · 8 comments
Open

Cannot download PNG file with iValue.download() method #186

ncalaway opened this issue Dec 3, 2021 · 8 comments

Comments

@ncalaway
Copy link
Collaborator

ncalaway commented Dec 3, 2021

Description

PNG files can't be downloaded using the .download() method. Possibly other files also have this problem. fsWriteSync throws an error that the file signature is invalid.

Steps to reproduce

  1. Save an img to a variable using context.exists()
  2. call .download on the variable; pass a file path as the first and only argument, saved as a PNG

Expected behavior

File downloaded correctly

Actual behavior

Invalid file signature error thrown; corrupt image file saved to filesystem

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 3, 2021

File signature when catting an image looks like:

�PNG

For both good and invalid PNGs.

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 3, 2021

Jpeg throws Crc error

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 3, 2021

File downloaded via Firefox and file downloaded via Flagpole have differences on every line when both are converted to hex.

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 6, 2021

Stripping out the needle.request() method and using it on its own correctly downloads the file. It is getting corrupted somewhere after that.

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 6, 2021

It is getting corrupted in the process of turning a Needle response into an HttpResponse

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 6, 2021

I think it's because the PNG buffer is being turned into a string with utf8 encoding. It should probably be base64.

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 6, 2021

There is corruption taking place even when I use base64

@ncalaway
Copy link
Collaborator Author

ncalaway commented Dec 6, 2021

The conversion of buffer to string in the constructor for HttpResponse is responsible for the corruption. What do I break if I take out the call to JSON.stringify()?

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

No branches or pull requests

1 participant