Skip to content

Zlib::GzipReader does not support #ungetc or #ungetbyte #4631

@haines

Description

@haines

Environment

jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [darwin-x86_64]

Expected Behavior

Zlib::GzipReader supports pushing data back onto the buffer via #ungetc and #ungetbyte.

# frozen_string_literal: true

require "zlib"

io = StringIO.new
writer = Zlib::GzipWriter.new(io)
writer.write "foo bar baz"
writer.close

reader = Zlib::GzipReader.new(StringIO.new(io.string))
reader.getc
reader.ungetc "b"
puts reader.read
$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

$ ruby gzip_reader_ungetc.rb
boo bar baz

$ ruby -r zlib -e "p Zlib::GzipReader.public_method_defined?(:ungetbyte)"
true

Actual Behavior

Zlib::GzipReader implements #ungetc as a no-op and does not respond to #ungetbyte.

$ ruby -v
jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [darwin-x86_64]

$ ruby gzip_reader_ungetc.rb
oo bar baz

$ ruby -r zlib -e "p Zlib::GzipReader.public_method_defined?(:ungetbyte)"
false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions