commit
8fb60eaec0
|
|
@ -21,9 +21,9 @@ require 'zip/null_compressor'
|
|||
require 'zip/null_input_stream'
|
||||
require 'zip/pass_thru_compressor'
|
||||
require 'zip/pass_thru_decompressor'
|
||||
require 'zip/encryption'
|
||||
require 'zip/null_encryption'
|
||||
require 'zip/traditional_encryption'
|
||||
require 'zip/crypto/encryption'
|
||||
require 'zip/crypto/null_encryption'
|
||||
require 'zip/crypto/traditional_encryption'
|
||||
require 'zip/inflater'
|
||||
require 'zip/deflater'
|
||||
require 'zip/streamable_stream'
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
module Zip
|
||||
class Encrypter #:nodoc:all
|
||||
end
|
||||
|
||||
class Decrypter
|
||||
end
|
||||
end
|
||||
|
||||
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
||||
# rubyzip is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the ruby license.
|
||||
|
|
@ -9,7 +9,7 @@ module Zip
|
|||
end
|
||||
end
|
||||
|
||||
class NullEncrypter
|
||||
class NullEncrypter < Encrypter
|
||||
include NullEncryption
|
||||
|
||||
def header(crc32)
|
||||
|
|
@ -24,7 +24,7 @@ module Zip
|
|||
end
|
||||
end
|
||||
|
||||
class NullDecrypter
|
||||
class NullDecrypter < Decrypter
|
||||
include NullEncryption
|
||||
|
||||
def decrypt(data)
|
||||
|
|
@ -35,3 +35,7 @@ module Zip
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
||||
# rubyzip is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the ruby license.
|
||||
|
|
@ -88,3 +88,7 @@ module Zip
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
||||
# rubyzip is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the ruby license.
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
module Zip
|
||||
class Encrypter #:nodoc:all
|
||||
def self.build(password)
|
||||
if password.nil? or password.empty?
|
||||
NullEncrypter.new
|
||||
else
|
||||
TraditionalEncrypter.new(password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Decrypter
|
||||
def self.build(password)
|
||||
if password.nil? or password.empty?
|
||||
NullDecrypter.new
|
||||
else
|
||||
TraditionalDecrypter.new(password)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -47,22 +47,18 @@ module Zip
|
|||
#
|
||||
# @param context [String||IO||StringIO] file path or IO/StringIO object
|
||||
# @param offset [Integer] offset in the IO/StringIO
|
||||
def initialize(context, offset = 0)
|
||||
def initialize(context, offset = 0, decrypter = nil)
|
||||
super()
|
||||
@archive_io = get_io(context, offset)
|
||||
@decompressor = ::Zip::NullDecompressor
|
||||
@decrypter = decrypter || ::Zip::NullDecrypter.new
|
||||
@current_entry = nil
|
||||
set_password(nil)
|
||||
end
|
||||
|
||||
def close
|
||||
@archive_io.close
|
||||
end
|
||||
|
||||
def set_password(password)
|
||||
@decrypter = ::Zip::Decrypter.build(password)
|
||||
end
|
||||
|
||||
# Returns a Entry object. It is necessary to call this
|
||||
# method on a newly created InputStream before reading from
|
||||
# the first entry in the archive. Returns nil when there are
|
||||
|
|
@ -96,8 +92,8 @@ module Zip
|
|||
# Same as #initialize but if a block is passed the opened
|
||||
# stream is passed to the block and closed when the block
|
||||
# returns.
|
||||
def open(filename_or_io, offset = 0)
|
||||
zio = self.new(filename_or_io, offset)
|
||||
def open(filename_or_io, offset = 0, decrypter = nil)
|
||||
zio = self.new(filename_or_io, offset, decrypter)
|
||||
return zio unless block_given?
|
||||
begin
|
||||
yield zio
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ module Zip
|
|||
|
||||
# Opens the indicated zip file. If a file with that name already
|
||||
# exists it will be overwritten.
|
||||
def initialize(file_name, stream=false)
|
||||
def initialize(file_name, stream=false, encrypter=nil)
|
||||
super()
|
||||
@file_name = file_name
|
||||
@output_stream = if stream
|
||||
|
|
@ -37,27 +37,27 @@ module Zip
|
|||
end
|
||||
@entry_set = ::Zip::EntrySet.new
|
||||
@compressor = ::Zip::NullCompressor.instance
|
||||
@encrypter = encrypter || ::Zip::NullEncrypter.new
|
||||
@closed = false
|
||||
@current_entry = nil
|
||||
@comment = nil
|
||||
set_password(nil)
|
||||
end
|
||||
|
||||
# Same as #initialize but if a block is passed the opened
|
||||
# stream is passed to the block and closed when the block
|
||||
# returns.
|
||||
class << self
|
||||
def open(file_name)
|
||||
def open(file_name, encrypter = nil)
|
||||
return new(file_name) unless block_given?
|
||||
zos = new(file_name)
|
||||
zos = new(file_name, false, encrypter)
|
||||
yield zos
|
||||
ensure
|
||||
zos.close if zos
|
||||
end
|
||||
|
||||
# Same as #open but writes to a filestream instead
|
||||
def write_buffer(io = ::StringIO.new(''))
|
||||
zos = new(io, true)
|
||||
def write_buffer(io = ::StringIO.new(''), encrypter = nil)
|
||||
zos = new(io, true, encrypter)
|
||||
yield zos
|
||||
zos.close_buffer
|
||||
end
|
||||
|
|
@ -119,10 +119,6 @@ module Zip
|
|||
@current_entry = nil
|
||||
end
|
||||
|
||||
def set_password(password)
|
||||
@encrypter = ::Zip::Encrypter.build(password)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finalize_current_entry
|
||||
|
|
|
|||
Loading…
Reference in New Issue