1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
# frozen_string_literal: true
module Zip
# The superclass for all rubyzip error types. Simply rescue this one if
# you don't need to know what sort of error has been raised.
class Error < StandardError; end
# Error raised if an unsupported compression method is used.
class CompressionMethodError < Error
# The compression method that has caused this error.
attr_reader :compression_method
# Create a new CompressionMethodError with the specified incorrect
# compression method.
def initialize(method)
super()
@compression_method = method
end
# The message returned by this error.
def message
"Unsupported compression method: #{COMPRESSION_METHODS[@compression_method]}."
end
end
# Error raised if there is a problem while decompressing an archive entry.
class DecompressionError < Error
# The error from the underlying Zlib library that caused this error.
attr_reader :zlib_error
# Create a new DecompressionError with the specified underlying Zlib
# error.
def initialize(zlib_error)
super()
@zlib_error = zlib_error
end
# The message returned by this error.
def message
"Zlib error ('#{@zlib_error.message}') while inflating."
end
end
# Error raised when trying to extract an archive entry over an
# existing file.
class DestinationExistsError < Error
# Create a new DestinationExistsError with the clashing destination.
def initialize(destination)
super()
@destination = destination
end
# The message returned by this error.
def message
"Cannot create file or directory '#{@destination}'. " \
'A file already exists with that name.'
end
end
# Error raised when trying to add an entry to an archive where the
# entry name already exists.
class EntryExistsError < Error
# Create a new EntryExistsError with the specified source and name.
def initialize(source, name)
super()
@source = source
@name = name
end
# The message returned by this error.
def message
"'#{@source}' failed. Entry #{@name} already exists."
end
end
# Error raised when an entry name is invalid.
class EntryNameError < Error
# Create a new EntryNameError with the specified name.
def initialize(name = nil)
super()
@name = name
end
# The message returned by this error.
def message
if @name.nil?
'Illegal entry name. Names must have fewer than 65,536 characters.'
else
"Illegal entry name '#{@name}'. Names must not start with '/'."
end
end
end
# Error raised if an entry is larger on extraction than it is advertised
# to be.
class EntrySizeError < Error
# The entry that has caused this error.
attr_reader :entry
# Create a new EntrySizeError with the specified entry.
def initialize(entry)
super()
@entry = entry
end
# The message returned by this error.
def message
"Entry '#{@entry.name}' should be #{@entry.size}B, but is larger when inflated."
end
end
# Error raised if a split archive is read. Rubyzip does not support reading
# split archives.
class SplitArchiveError < Error
# The message returned by this error.
def message
'Rubyzip cannot extract from split archives at this time.'
end
end
# Error raised if there is not enough metadata for the entry to be streamed.
class StreamingError < Error
# The entry that has caused this error.
attr_reader :entry
# Create a new StreamingError with the specified entry.
def initialize(entry)
super()
@entry = entry
end
# The message returned by this error.
def message
"The local header of this entry ('#{@entry.name}') does not contain " \
'the correct metadata for `Zip::InputStream` to be able to ' \
'uncompress it. Please use `Zip::File` instead of `Zip::InputStream`.'
end
end
end
|