Module: Omnizip::Formats::Tar

Defined in:
lib/omnizip/formats/tar.rb,
lib/omnizip/formats/tar/entry.rb,
lib/omnizip/formats/tar/header.rb,
lib/omnizip/formats/tar/reader.rb,
lib/omnizip/formats/tar/writer.rb,
lib/omnizip/formats/tar/constants.rb

Overview

TAR archive format implementation

TAR (Tape Archive) is a simple archive format that bundles files without compression. It's commonly used in combination with compression formats like GZIP (.tar.gz) or BZIP2 (.tar.bz2).

This implementation supports POSIX ustar format with:

  • Regular files
  • Directories
  • Symbolic links
  • Hard links
  • Metadata preservation (permissions, timestamps, ownership)

Defined Under Namespace

Modules: Constants Classes: Entry, Header, Reader, Writer

Class Method Summary collapse

Class Method Details

.create(file_path) {|Writer| ... } ⇒ Writer

Create a TAR archive

rubocop:disable Naming/BlockForwarding, Style/ArgumentsForwarding -- Ruby 3.0 compatibility

Parameters:

  • file_path (String)

    Path to output TAR archive

Yields:

  • (Writer)

    TAR writer instance

Returns:

  • (Writer)

    TAR writer instance



51
52
53
# File 'lib/omnizip/formats/tar.rb', line 51

def create(file_path, &block)
  Writer.create(file_path, &block)
end

.extract(file_path, output_dir) ⇒ Object

Extract a TAR archive

Parameters:

  • file_path (String)

    Path to TAR archive

  • output_dir (String)

    Output directory



60
61
62
63
# File 'lib/omnizip/formats/tar.rb', line 60

def extract(file_path, output_dir)
  reader = read(file_path)
  reader.extract_all(output_dir)
end

.list(file_path) ⇒ Array<Entry>

List entries in a TAR archive

Parameters:

  • file_path (String)

    Path to TAR archive

Returns:

  • (Array<Entry>)

    List of entries



69
70
71
72
# File 'lib/omnizip/formats/tar.rb', line 69

def list(file_path)
  reader = read(file_path)
  reader.list_entries
end

.open(file_path) {|Reader| ... } ⇒ Reader

Open a TAR archive with block syntax

rubocop:disable Naming/BlockForwarding, Style/ArgumentsForwarding -- Ruby 3.0 compatibility

Parameters:

  • file_path (String)

    Path to TAR archive

Yields:

  • (Reader)

    TAR reader instance

Returns:

  • (Reader)

    TAR reader instance



40
41
42
# File 'lib/omnizip/formats/tar.rb', line 40

def open(file_path, &block)
  Reader.open(file_path, &block)
end

.read(file_path) ⇒ Reader

Read a TAR archive

Parameters:

  • file_path (String)

    Path to TAR archive

Returns:

  • (Reader)

    TAR reader instance



30
31
32
# File 'lib/omnizip/formats/tar.rb', line 30

def read(file_path)
  Reader.new(file_path).read
end

.register!Object

Register TAR format when loaded



75
76
77
# File 'lib/omnizip/formats/tar.rb', line 75

def register!
  FormatRegistry.register(".tar", Omnizip::Formats::Tar)
end