-
Notifications
You must be signed in to change notification settings - Fork 374
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
added: fileSourceByteString #1503
Conversation
This function is to get `FileInfo` raw body.
yesod-core/Yesod/Core/Handler.hs
Outdated
-- | ||
-- @since 1.6.4 | ||
fileSourceByteString :: MonadResource m => FileInfo -> m S.ByteString | ||
fileSourceByteString fileInfo = fileSource fileInfo `connect` CL.foldMap id |
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.
There are a few problems with this implementation:
CL.foldMap id
has quadratic complexity. It would be better to use something likesinkLazy
- It's more common to use
runConduit $ src .| sink
How about:
runConduit $ fileSource fileInfo .| Conduit.
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.
I use runConduit
.
But fileSource
function result strict ByteString
.
So I think can't use sinkLazy
.
Do you think?
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.
You'd have to use Data.ByteString.toStrict
, but that's more efficient than using foldMap
.
yesod-core/Yesod/Core/Handler.hs
Outdated
@@ -1360,6 +1361,16 @@ rawRequestBody = do | |||
fileSource :: MonadResource m => FileInfo -> ConduitT () S.ByteString m () | |||
fileSource = transPipe liftResourceT . fileSourceRaw | |||
|
|||
-- | Strict `ByteString` body from `FileInfo`. | |||
-- This function blocking while read file. |
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.
Can you reword this comment to something like:
Extract a strict `ByteString` body from a `FileInfo`.
This function will block while reading the file.
@snoyberg I think that |
@snoyberg |
Returning a lazy |
@snoyberg So, I use |
|
@snoyberg |
It refers to the performance.
…On Tue, Apr 24, 2018, 2:03 PM ncaq ***@***.***> wrote:
@snoyberg <https://github.com/snoyberg>
Sorry, What are "complexity" mean code clearing or performance?
I understood to code clearing.
So, I try to write clear code.
But, Are you speak performance?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1503 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADBByLD5-n7thrburn-unt8EwyggqiNks5trwaQgaJpZM4TXpqz>
.
|
Because performance problem.
@snoyberg I rewrite. |
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.
Thanks!
This function is to get
FileInfo
raw body.Conduit type is hard for begginer user.
Actually I was not sure when I was a Haskell beginner.
ByteString raw body of
FileInfo
is need to upload file to S3.This function running our product.
I send it to upstream.
Before submitting your PR, check that you've:
@since
declarations to the Haddocks for new, public APIsAfter submitting your PR: