class MemTar
In-memory tar archive writer.
Constants
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/memtar.rb, line 8 def initialize @io = StringIO.new end
opts_of_stat(stat)
click to toggle source
# File lib/memtar.rb, line 36 def self.opts_of_stat stat uid, gid = [stat.uid, stat.gid] { mode: stat.mode & 0777, uid: uid, gid: gid, uname: Etc.getpwuid(uid).name, gname: Etc.getgrgid(gid).name, mtime: stat.mtime } end
Public Instance Methods
add_existing_file(path, file)
click to toggle source
# File lib/memtar.rb, line 27 def add_existing_file path, file stat = file.lstat if stat.symlink? add_symlink path, File.readlink(file.path) else add_file path, file.read, MemTar.opts_of_stat(stat) end end
add_file(path, content, opts = {})
click to toggle source
# File lib/memtar.rb, line 12 def add_file path, content, opts = {} return add_existing_file path, content if content.is_a?(File) && opts.empty? fail ArgumentError, "handling of paths over 100 bytes long not implemented" if path.size > 100 size = content.bytesize @io.write header opts.merge size: size, name: path @io.write content @io.write "\0" * ((512 - size % 512) % 512) end
add_symlink(path, target)
click to toggle source
# File lib/memtar.rb, line 22 def add_symlink path, target fail ArgumentError, "handling of paths over 100 bytes long not implemented" if path.size > 100 @io.write header typeflag: '2', size: 0, mode: 0777, name: path, linkname: target end
default()
click to toggle source
# File lib/memtar.rb, line 55 def default @default ||= { mode: 0644, uid: 0, gid: 0, uname: 'wheel', gname: 'wheel', mtime: Time.now, prefix: '' } end
header(opts)
click to toggle source
# File lib/memtar.rb, line 51 def header opts Archive::Tar::Minitar::PosixHeader.new(default.merge(opts)).to_s end
to_s()
click to toggle source
# File lib/memtar.rb, line 47 def to_s @io.string + "\0" * 1024 end