Skip to content

Fix the arguments and return values of Zlib::GzipReader's line and byte methods - #3330

Open
hasannadeem wants to merge 1 commit into
ruby:masterfrom
hasannadeem:gzip-reader-lines
Open

hasannadeem wants to merge 1 commit into
ruby:masterfrom
hasannadeem:gzip-reader-lines

Conversation

@hasannadeem

Copy link
Copy Markdown
Contributor

This PR fixes the arguments and return values of Zlib::GzipReader's line and byte methods, as zlib.c implements them.

Line methods

gets, readline, readlines, each and each_line all go through gzreader_gets. Like IO#gets, it takes a nil separator (read to the end), a lone limit, or a nil limit after a separator. The signatures only allowed (?String sep, ?Integer limit):

gz.gets(nil)          # => "ab\ncd\n\nef\n"
gz.gets(3)            # => "ab\n"
gz.readlines(nil, 4)  # => ["ab\nc", "d\n\ne", "f\n"]

each and each_line were typed as (*untyped) { (String) -> void } -> void. They return the reader, and without a block they return an Enumerator.

gzreader_gets scans "11", with no keywords, so there is no chomp: here. gz.gets(chomp: true) raises TypeError ("no implicit conversion of Hash into Integer"), and the signatures don't add it.

Byte and char methods

  • each_byte yields Integers, not Strings.
  • each_byte and each_char return nil with a block. Without one they return an Enumerator, which the signatures didn't allow.
  • ungetc also takes an Integer. rb_gzreader_ungetc hands a Fixnum to ungetbyte, and anything else goes through StringValue.

Not typed

Without a block, each_line(2) returns an Enumerator over whole lines: RETURN_ENUMERATOR(obj, 0, 0) drops the arguments. So the blockless overload takes no arguments.

Checked

…te methods

GzipReader#gets, #readline, #readlines, #each and #each_line take a nil
separator, a lone limit and a nil limit, like IO#gets. #each and
#each_line return the reader, and without a block return an
Enumerator. #each_byte yields Integers, and #each_byte and #each_char
return nil, or an Enumerator without a block. #ungetc also takes an
Integer, which it pushes back as a byte.
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.

1 participant