Skip to content
Browse files

archive-zip patch for Ruby1.9.2 (part2).

  • Loading branch information...
1 parent 86f7e45 commit ec8475b3c36763d41a861331e4d688a7084c4783 @ongaeshi committed Aug 4, 2011
Showing with 55 additions and 35 deletions.
  1. +2 −35 lib/milkode/common/archive-zip.rb
  2. +53 −0 vendor/archive/support/io.rb
View
37 lib/milkode/common/archive-zip.rb
@@ -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'
View
53 vendor/archive/support/io.rb
@@ -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

0 comments on commit ec8475b

Please sign in to comment.
Something went wrong with that request. Please try again.