Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Conversation

@jkap
Copy link
Contributor

@jkap jkap commented Apr 18, 2023

  • API is now more strict about requiring an integer for contentLength. Numeric strings are no longer accepted.
  • width and height are now available (albeit optional) fields. Including these is preferred. I included an implementation for this, although I am amateurish at rust so my way of getting around borrowing path after moving (clones!) is probably incorrect. Would love to know what's actually idiomatic here.

Tested this works as expected with no changes required for examples/post.rs.

- API is now more strict about requiring an integer for `contentLength`.
  Numeric strings are no longer accepted.
- `width` and `height` are now available (albeit optional) fields.
  Including these is preferred. I included an implementation for this,
  although I am amateurish at rust so my way of getting around borrowing
  `path` probably is incorrect. Would love to know what's actually
  idiomatic here.

Tested this works as expected with no changes required for `examples/post.rs`.
Copy link
Owner

@iliana iliana left a comment

Choose a reason for hiding this comment

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

Ooh, imagesize is a really smol library. Good find; I would have otherwise recommended making that an optional dependency but I think there's no need.

.to_owned();

let file = File::open(path).await?;
let file = File::open(path.clone()).await?;
Copy link
Owner

Choose a reason for hiding this comment

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

The usual way I handle this is, at the top of the function, writing something like:

let path = path.as_ref();

path becomes a &Path, which also impls AsRef<Path>, so it can be passed to both functions without a clone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sick thank you! constantly learning new things

let file = File::open(path).await?;
let file = File::open(path.clone()).await?;
let content_length = file.metadata().await?.len();
let stream = Body::wrap_stream(FramedRead::new(file, BytesCodec::new()));
Copy link
Owner

Choose a reason for hiding this comment

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

An alternative implementation could use imagesize::reader_size with &mut file here, before moving the file into this Body.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tried this at first but couldn't really finagle it into working. probably just something i Don't Know but didn't really want to keep fucking with it

@jkap
Copy link
Contributor Author

jkap commented Apr 18, 2023

Ooh, imagesize is a really smol library. Good find; I would have otherwise recommended making that an optional dependency but I think there's no need.

made it optional anyway so that i can learn how to do that (happy to undo that though)

@iliana
Copy link
Owner

iliana commented Apr 18, 2023

Can you test building with cargo build --no-default-features? I think it will fail to compile in this state but I'm only looking at it with my sleepy-Tuesday brain and not a compiler.

@jkap
Copy link
Contributor Author

jkap commented Apr 18, 2023

all good, still builds

@iliana iliana merged commit 94fc2f6 into iliana:main Apr 18, 2023
@iliana
Copy link
Owner

iliana commented Apr 18, 2023

Thanks! If I don't get terribly distracted I'll get a release out.

@jam1garner
Copy link

Tested and working for me as well

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants