-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
archive-zip patch for Ruby1.9.2 (part2).
- Loading branch information
Showing
2 changed files
with
55 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# @file | ||
# @brief archive-zipがRuby1.9.2に対応するまでのパッチ、readbytesが無ければ実装する | ||
# @brief archive-zipがRuby1.9.2に対応するまでのパッチ | ||
# @author ongaeshi | ||
# @date 2011/08/04 | ||
|
||
begin | ||
require 'readbytes' | ||
rescue LoadError | ||
# for Ruby 1.9.2 | ||
class TruncatedDataError<IOError | ||
def initialize(mesg, data) # :nodoc: | ||
@data = data | ||
super(mesg) | ||
end | ||
|
||
# The read portion of an IO#readbytes attempt. | ||
attr_reader :data | ||
end | ||
|
||
class IO | ||
# Reads exactly +n+ bytes. | ||
# | ||
# If the data read is nil an EOFError is raised. | ||
# | ||
# If the data read is too short a TruncatedDataError is raised and the read | ||
# data is obtainable via its #data method. | ||
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 | ||
end | ||
|
||
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../../../vendor') | ||
require 'archive/zip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# @file | ||
# @brief archive-zip/lib/archive/support/io.rb patch, removed in the future. | ||
# @author ongaeshi | ||
# @date 2011/08/04 | ||
|
||
begin | ||
require 'readbytes' | ||
rescue LoadError | ||
# for Ruby 1.9.2 | ||
class TruncatedDataError<IOError | ||
def initialize(mesg, data) # :nodoc: | ||
@data = data | ||
super(mesg) | ||
end | ||
|
||
# The read portion of an IO#readbytes attempt. | ||
attr_reader :data | ||
end | ||
|
||
class IO | ||
# Reads exactly +n+ bytes. | ||
# | ||
# If the data read is nil an EOFError is raised. | ||
# | ||
# If the data read is too short a TruncatedDataError is raised and the read | ||
# data is obtainable via its #data method. | ||
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 | ||
end | ||
|
||
class IO | ||
# Returns +true+ if the seek method of this IO instance would succeed, +false+ | ||
# otherwise. | ||
def seekable? | ||
begin | ||
pos | ||
true | ||
rescue SystemCallError | ||
false | ||
end | ||
end | ||
end |