Skip to content

Instantly share code, notes, and snippets.

@jhchabran
Created March 23, 2009 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhchabran/83760 to your computer and use it in GitHub Desktop.
Save jhchabran/83760 to your computer and use it in GitHub Desktop.
class IO
def readbytes(n)
str = read(n)
if str == nil
raise EOFError, "End of file reached"
end
if str.size < n
raise TruncatedDataError.new("data truncated", str)
end
str
end
end
# little hack to tame Archive/Zip which requires 'readbytes'
# :nodoc:
module Kernel
def require_with_readbytes_hack(something)
return true if something == 'readbytes'
require_without_readbytes_hack something
end
alias_method :require_without_readbytes_hack,
:require
alias_method :require,
:require_with_readbytes_hack
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment