2021-05-24 01:24:22 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-15 06:00:27 +08:00
|
|
|
module Zip
|
2022-11-07 05:26:37 +08:00
|
|
|
# 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.
|
2014-01-24 17:37:38 +08:00
|
|
|
class Error < StandardError; end
|
2021-11-27 19:02:29 +08:00
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised if an unsupported compression method is used.
|
2021-11-27 19:02:29 +08:00
|
|
|
class CompressionMethodError < Error
|
|
|
|
attr_reader :compression_method
|
|
|
|
|
|
|
|
def initialize(method)
|
|
|
|
super()
|
|
|
|
@compression_method = method
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"Unsupported compression method: #{COMPRESSION_METHODS[@compression_method]}."
|
|
|
|
end
|
|
|
|
end
|
2021-11-29 00:51:06 +08:00
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised if there is a problem while decompressing an archive entry.
|
2022-08-14 23:31:03 +08:00
|
|
|
class DecompressionError < Error
|
|
|
|
attr_reader :zlib_error
|
|
|
|
|
|
|
|
def initialize(zlib_error)
|
|
|
|
super()
|
|
|
|
@zlib_error = zlib_error
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"Zlib error ('#{@zlib_error.message}') while inflating."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised when trying to extract an archive entry over an
|
|
|
|
# existing file.
|
2022-08-16 18:13:30 +08:00
|
|
|
class DestinationExistsError < Error
|
|
|
|
def initialize(destination)
|
|
|
|
super()
|
|
|
|
@destination = destination
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"Cannot create file or directory '#{@destination}'. " \
|
2024-03-02 06:14:48 +08:00
|
|
|
'A file already exists with that name.'
|
2022-08-16 18:13:30 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised when trying to add an entry to an archive where the
|
|
|
|
# entry name already exists.
|
2022-08-15 05:05:42 +08:00
|
|
|
class EntryExistsError < Error
|
|
|
|
def initialize(source, name)
|
|
|
|
super()
|
|
|
|
@source = source
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"'#{@source}' failed. Entry #{@name} already exists."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised when an entry name is invalid.
|
2022-08-16 17:52:18 +08:00
|
|
|
class EntryNameError < Error
|
|
|
|
def initialize(name = nil)
|
|
|
|
super()
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised if an entry is larger on extraction than it is advertised
|
|
|
|
# to be.
|
2022-08-16 05:02:33 +08:00
|
|
|
class EntrySizeError < Error
|
|
|
|
attr_reader :entry
|
|
|
|
|
|
|
|
def initialize(entry)
|
|
|
|
super()
|
|
|
|
@entry = entry
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"Entry '#{@entry.name}' should be #{@entry.size}B, but is larger when inflated."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised if a split archive is read. Rubyzip does not support reading
|
|
|
|
# split archives.
|
2022-08-14 18:30:43 +08:00
|
|
|
class SplitArchiveError < Error
|
|
|
|
def message
|
|
|
|
'Rubyzip cannot extract from split archives at this time.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-07 05:26:37 +08:00
|
|
|
# Error raised if there is not enough metadata for the entry to be streamed.
|
2021-11-29 00:51:06 +08:00
|
|
|
class StreamingError < Error
|
|
|
|
attr_reader :entry
|
|
|
|
|
|
|
|
def initialize(entry)
|
|
|
|
super()
|
|
|
|
@entry = entry
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
"The local header of this entry ('#{@entry.name}') does not contain " \
|
2024-03-02 06:14:48 +08:00
|
|
|
'the correct metadata for `Zip::InputStream` to be able to ' \
|
|
|
|
'uncompress it. Please use `Zip::File` instead of `Zip::InputStream`.'
|
2021-11-29 00:51:06 +08:00
|
|
|
end
|
|
|
|
end
|
2013-08-15 06:00:27 +08:00
|
|
|
end
|