Method: Rex::Zip::Archive#add_file

Defined in:
lib/rex/zip/archive.rb

#add_file(fname, fdata = nil, xtra = nil, comment = nil, central_dir_name = nil) ⇒ Object

Create a new Entry and add it to the archive.

If fdata is set, the file is populated with that data from the calling method. If fdata is nil, then the fs is checked for the file. If central_dir_name is set it will be used to spoof the name at the Central Directory at packing time.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rex/zip/archive.rb', line 45

def add_file(fname, fdata=nil, xtra=nil, comment=nil, central_dir_name=nil)
  if (not fdata)
    begin
      st = File.stat(fname)
    rescue
      return nil
    end

    ts = st.mtime
    if (st.directory?)
      attrs = EFA_ISDIR
      fdata = ''
      unless fname[-1,1] == '/'
        fname += '/'
      end
    else
      f = File.open(fname, 'rb')
      fdata = f.read(f.stat.size)
      f.close
    end
  end

  @entries << Entry.new(fname, fdata, @compmeth, ts, attrs, xtra, comment, central_dir_name)
end