Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update openimg to v0.6
Details
The new version of openimg now correctly includes the
content-type
andcontent-length
headers in all cases. This ensures that saved images always have the correct file extension attached by the browser. The update also adds ametadata.json
file to the cache if you want to check that out!Background
I don't want to load the image into memory at once but stream it. However, that makes retrieving the image metadata tricky. The source of truth is sharp, but retrieving the metadata of an image from sharp while streaming it directly out to the client is tricky. HTTP headers must be set before the body starts streaming, but sharp needs to process parts of the image before the metadata is available. I was finally able to figure this out with a
PassThrough
stream that buffers chunks until the metadata is available and only then starts streaming it out to the client (relevant changes here). A newmetadata.json
file now stores image metadata for cached files. This is inspired by mjackson's local-file-storage! I tested it out on allthingsweb, and things seem to work. :)Before
Added
jpeg
extension to image on download even though real content-type was png.After
Test Plan