Sha256: f3c5660ab959772fc20dd25db9b04e320b31ad3f2977e310fdc5f4aa08edf282

Contents?: true

Size: 928 Bytes

Versions: 20

Compression:

Stored size: 928 Bytes

Contents

class UnzipJob < ActiveFedoraPidBasedJob
  def queue_name
    :unzip
  end

  def run
    Zip::Archive.open_buffer(object.content.content) do |archive|
      archive.each do |f|
        if f.directory?
          create_directory(f)
        else
          create_file(f)
        end
      end
    end
  end

  protected

  # Creates a GenericFile object based on +file+
  # @param file [Zip::File]
  def create_file(file)
    @generic_file = GenericFile.new
    @generic_file.batch_id = object.batch.pid
    @generic_file.add_file(file.read, 'content', file.name)
    @generic_file.apply_depositor_metadata(object.edit_users.first)
    @generic_file.date_uploaded = Time.now.ctime
    @generic_file.date_modified = Time.now.ctime
    @generic_file.save
  end
  
  # Creates representation of directory corresponding to +file+
  # Default behavior: _do nothing_
  # @param file [Zip::File]
  def create_directory(file)
  end

end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
sufia-3.5.0 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.5.0 lib/sufia/models/jobs/unzip_job.rb
sufia-3.4.0 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.4.0 lib/sufia/models/jobs/unzip_job.rb
sufia-3.4.0.rc4 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.4.0.rc4 lib/sufia/models/jobs/unzip_job.rb
sufia-3.4.0.rc3 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.4.0.rc3 lib/sufia/models/jobs/unzip_job.rb
sufia-3.3.1 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.3.1 lib/sufia/models/jobs/unzip_job.rb
sufia-3.4.0.rc2 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.4.0.rc2 lib/sufia/models/jobs/unzip_job.rb
sufia-3.4.0.rc1 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.4.0.rc1 lib/sufia/models/jobs/unzip_job.rb
sufia-3.3.0 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.3.0 lib/sufia/models/jobs/unzip_job.rb
sufia-3.2.1 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.2.1 lib/sufia/models/jobs/unzip_job.rb
sufia-3.1.3 sufia-models/lib/sufia/models/jobs/unzip_job.rb
sufia-models-3.1.3 lib/sufia/models/jobs/unzip_job.rb