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 IO#getb_to_end #11830

Merged

Conversation

HertzDevil
Copy link
Contributor

Resolves #11586. There is also an optimization for IO::Memory that skips IO.copy (a copy is still made so that changes to the IO don't affect the returned Bytes).

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

I believe the #getb_to_end override needs a call to check_open.

src/io/memory.cr Outdated Show resolved Hide resolved
@asterite
Copy link
Member

I believe the #getb_to_end override needs a call to check_open.

I'm not sure, gets_to_end doesn't do that. Because it will call read, that will check if it's open.

@straight-shoota
Copy link
Member

I mean IO::Memory#getb_to_end.

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

Looks good!

Maybe offtopic, but will there be other such methods...? For example getb to get a line or up to a delimiter as Bytes.

@HertzDevil
Copy link
Contributor Author

#getb was indeed briefly mentioned in the original issue, I haven't created a separate issue but a good candidate would be reading bytes delimited by the zero byte.

@straight-shoota straight-shoota added this to the 1.4.0 milestone Mar 10, 2022
@straight-shoota straight-shoota merged commit bffef0f into crystal-lang:master Mar 14, 2022
@HertzDevil HertzDevil deleted the feature/io-getb_to_end branch March 14, 2022 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reading or writing a binary file with Bytes
3 participants