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

Add ByteString.Lazy utilities #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

berewt
Copy link

@berewt berewt commented Nov 21, 2017

The starting point was a similar issue from the one raised in #209. Compared to the solution proposed in the thread, I'd prefer to go for a whole set of utilities for ByteString.Lazy. It allows almost the same shell facilities than the strict version, except that chunks are meaningless here.

@Gabriella439
Copy link
Owner

Wow, thanks for doing this! Give me a day or two to review this more closely, but I approve of the overall direction of this

{-| Read lazily bytes from standard input

-}
stdin :: Shell ByteString
Copy link
Owner

Choose a reason for hiding this comment

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

Should this have type:

stdin :: MonadIO io => io ByteString


The chunks are not necessarily aligned to line boundaries
-}
input :: FilePath -> Shell ByteString
Copy link
Owner

Choose a reason for hiding this comment

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

Should this have type:

input :: MonadManaged managed => FilePath -> managed ByteString


Throws an `ExitCode` exception if the command returns a non-zero exit code
-}
stream
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think you need any of the streaming functions like stream/streamWithErr or the functions downstream of them. The systemStrict and systemStrictWithErr versions already stream since they are using Data.ByteString.Lazy.hGetContents

@berewt
Copy link
Author

berewt commented Nov 24, 2017

Regarding the signature changes: yep, I forgot to transitively generalise the functions that depends on inhandle, thanks.

Regarding the stream / streamWithErr, maybe I should only keep the strict version and rename them as stream and streamWithErr, as the strict names can be misleading, what do you think about it?

@Gabriella439
Copy link
Owner

Yeah, I agree that they don't need the strict in the names for this module

@berewt
Copy link
Author

berewt commented Nov 24, 2017

One more question then, if we remove stream / streamWithError in favour of systemStrict / systemStrictWithError, what do we do with function like inProc, that was previously relying on stream, and will now use systemStrict:

  1. keep their signature as is and discard the ExitCode;
  2. change them, to include the ExitCode?

@Gabriella439
Copy link
Owner

I think you don't even inproc any longer since proc and the new stream utility supersede it

Or you could rename the new stream utility to inproc instead for conceptual consistency

@berewt
Copy link
Author

berewt commented Nov 24, 2017

I finally decided to drop the in* function and went for a *Stream name instead. The names are consistent with the *Strict equivalent in Turtle.ByteString. Please do not hesitate to propose something else if you're not happy with the result, I'm not totally satisfied myself either. ;-)

-- ^ Command
-> Shell ByteString
-- ^ Chunks of bytes written to process input
-> io (ExitCode, ByteString)
Copy link
Owner

Choose a reason for hiding this comment

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

Actually, something seems wrong here. This type implies that we have access to the ExitCode as the same time as the ByteString, which is being read lazily. If we are able to access the ExitCode, wouldn't that imply that the reading ByteString would fail due to the subprocess handle being closed?

Copy link
Author

Choose a reason for hiding this comment

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

I guess that I should have port the initial stream version as well then... I should really try and test these functions with some examples, I'm not sure whether the out handle will be accessible or not in that case.

Copy link
Owner

Choose a reason for hiding this comment

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

One option would be to read the lazy ByteString strictly (i.e. force the entire ByteString) so that you don't have to worry about still reading it after the handle is closed

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