class EventMachine::Zipper::Base

Attributes

files[R]
fqueue[R]
zos[R]

Public Class Methods

new(files, zos) click to toggle source
# File lib/em-zipper/base.rb, line 10
def initialize(files, zos)
  @files  = files
  @zos    = zos
  @fqueue = EM::Queue.new
  @count  = 0
end

Public Instance Methods

zip!() click to toggle source
# File lib/em-zipper/base.rb, line 17
def zip!
  files.each do |file_path|
    EM.next_tick { chunk_data(file_path) }
  end
  fqueue.pop(&write_entry) # begin queue, first file to chunk will be issued this call

  self # ...new(..., ...).zip!
end

Private Instance Methods

chunk_data(file_path) click to toggle source
# File lib/em-zipper/base.rb, line 52
def chunk_data(file_path)
  chunks = Chunks.new(file_path).chop!
  chunks.callback do |chunk_q|
    EM.next_tick { fqueue.push [file_path, chunk_q] }
  end
end
close_zos() click to toggle source
# File lib/em-zipper/base.rb, line 29
def close_zos
  zos.close if zos.io.is_a?(File) # close the io if it's a file
  succeed zos.close_buffer        # return the zos
end
write_entry() click to toggle source
# File lib/em-zipper/base.rb, line 34
def write_entry
  proc do |args|
    file_path = args[0]
    q         = args[1]

    entry = Entry.new(file_path, q, zos).write!
    entry.callback do
      @count = @count + 1

      if files.size == @count
        close_zos
      else
        EM.next_tick { fqueue.pop(&write_entry) }
      end
    end
  end
end