Add InputStream#ungetc

Works like IO#ungetc
This commit is contained in:
Zac Stewart 2014-03-11 21:19:24 -04:00
parent 2697c7ea4f
commit 96377f72de
2 changed files with 15 additions and 1 deletions

View File

@ -86,6 +86,10 @@ module Zip
return @output_buffer.slice!(0...sep_index) return @output_buffer.slice!(0...sep_index)
end end
def ungetc(byte)
@output_buffer.prepend(byte.chr)
end
def flush def flush
ret_val = @output_buffer ret_val = @output_buffer
@output_buffer = '' @output_buffer = ''

View File

@ -157,4 +157,14 @@ class ZipInputStreamTest < MiniTest::Unit::TestCase
} }
end end
def test_ungetc
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
zis.get_next_entry
first_line = zis.gets.chomp
first_line.bytes.reverse.each { |b| zis.ungetc(b) }
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
assert_equal("$VERBOSE =", zis.read(10))
end
end
end end