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

Ensure empty files do not have a mimetype #104

Merged
merged 1 commit into from
Feb 17, 2022
Merged

Conversation

wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Feb 15, 2022

Today it seems that non-nil readers to files with no contents are resulting in text/plain MIME types, which is incorrect. We should return no MIME type. This PR makes this adjustment by ensuring the size of read bytes is not 0.

Related to anchore/syft#782

@wagoodman wagoodman requested a review from a team February 15, 2022 23:57
@wagoodman wagoodman self-assigned this Feb 15, 2022
@github-actions
Copy link

github-actions bot commented Feb 15, 2022

Benchmark Test Results

Benchmark results from the latest changes vs base branch
name                                old time/op    new time/op    delta
pkg:github.com/anchore/stereoscope/pkg/file goos:linux goarch:amd64
TarIndex-2                            54.2µs ± 1%    58.9µs ± 2%   +8.51%  (p=0.029 n=4+4)
pkg:github.com/anchore/stereoscope/test/integration goos:linux goarch:amd64
SimpleImage_GetImage/FromTarball-2    1.85ms ± 6%    2.04ms ± 4%  +10.15%  (p=0.016 n=5+5)

name                                old alloc/op   new alloc/op   delta
pkg:github.com/anchore/stereoscope/pkg/file goos:linux goarch:amd64
TarIndex-2                            8.38kB ± 0%    8.38kB ± 0%     ~     (p=1.000 n=4+4)
pkg:github.com/anchore/stereoscope/test/integration goos:linux goarch:amd64
SimpleImage_GetImage/FromTarball-2     409kB ± 0%     402kB ± 0%   -1.82%  (p=0.008 n=5+5)

name                                old allocs/op  new allocs/op  delta
pkg:github.com/anchore/stereoscope/pkg/file goos:linux goarch:amd64
TarIndex-2                               205 ± 0%       205 ± 0%     ~     (all equal)
pkg:github.com/anchore/stereoscope/test/integration goos:linux goarch:amd64
SimpleImage_GetImage/FromTarball-2     4.66k ± 0%     4.40k ± 0%   -5.46%  (p=0.029 n=4+4)

expected: "text/plain",
},
{
// no contents
fixture: "",
name: "no contents",
Copy link
Contributor

@jonasagx jonasagx Feb 16, 2022

Choose a reason for hiding this comment

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

Maybe add a directory example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since this function takes a reader it's not possible to pass it a directory

Copy link
Contributor

@jonasagx jonasagx left a comment

Choose a reason for hiding this comment

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

LGTM with a test suggestion

@wagoodman wagoodman merged commit c6f02ae into main Feb 17, 2022
@wagoodman wagoodman deleted the fix-empty-mimetype branch February 17, 2022 14:14
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