-
Notifications
You must be signed in to change notification settings - Fork 50
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
Remove IO.blocking from array copy in S3 client. #1265
base: main
Are you sure you want to change the base?
Conversation
Async[F].blocking { | ||
val bs = resp.asByteArray() | ||
val len = bs.length | ||
if (len < 0) None else Some(Chunk(unsafeWrapArray(bs)*)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why are we checking to see if the array size is negative? What would that even mean? This SO post says that can't happen: https://stackoverflow.com/a/11530038/283260
Should this just always return Some
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a second commit removing this length check.
* Also remove the array copy - using `.asByteArrayUnsafe` instead of `.asByteArray` to return the original byte array without making a copy of it. FS2 doesn't mutate the byte array afaict, and this `readFileMultipart` method returns a `fs2.Stream[F, Byte]` - the caller isn't going to be able to mutate those Bytes. * Also removed the `Monad.ifM`. `ifM(pure(x))(t, f)` is the same as `if (x) t else false`. * Construct the `Chunk`s from byte arrays in a more direct fashion.
Consolidate two subsequent `.flatMap`s into one.
db2d22e
to
b7d78a3
Compare
Async[F].pure((Option.empty[ETag], Option.empty[Checksum], Option.empty[PartId])) | ||
) | ||
cancelUpload(uploadId) *> ( | ||
if (uploadEmptyFiles) uploadEmptyFile.map(eTag => Option(eTag.eTag)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also do these two lines w/ like a OptionT.whenF(uploadEmptyFiles)(uploadEmptyFile)
, etc...
Also remove the array copy - using
.asByteArrayUnsafe
instead of.asByteArray
to return the original byte array without making a copy of it. FS2 doesn't mutate the byte array afaict, and thisreadFileMultipart
method returns afs2.Stream[F, Byte]
- the caller isn't going to be able to mutate those Bytes.Also removed the
Monad.ifM
.ifM(pure(x))(t, f)
is the same asif (x) t else f
.Construct the
Chunk
s from byte arrays in a more direct fashion.