# frozen_string_literal: true
#
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# ronin-support is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-support is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-support.  If not, see <https://www.gnu.org/licenses/>.
#

require 'ronin/support/archive/tar/reader'
require 'ronin/support/archive/tar/writer'
require 'ronin/support/archive/zip/reader'
require 'ronin/support/archive/zip/writer'

class File

  #
  # Opens the tar archive file for reading.
  #
  # @param [String] path
  #   The path to the file to read.
  #
  # @yield [tar]
  #   If a block is given, it will be passed the tar reader object.
  #
  # @yieldparam [Ronin::Support::Archive::Tar::Reader] tar
  #   The tar reader object.
  #
  # @return [Ronin::Support::Archive::Tar::Reader]
  #   The tar reader object.
  #
  # @api public
  #
  # @since 1.0.0
  #
  def self.untar(path,&block)
    Ronin::Support::Archive::Tar::Reader.open(path,&block)
  end

  #
  # Opens the tar archive file for writing.
  #
  # @param [String] path
  #   The path to the file to write to.
  #
  # @yield [tar]
  #   If a block is given, it will be passed the tar writer object.
  #
  # @yieldparam [Ronin::Support::Archive::Tar::Writer] tar
  #   The tar writer object.
  #
  # @return [Ronin::Support::Archive::Tar::Writer]
  #   The tar writer object.
  #
  # @api public
  #
  # @since 1.0.0
  #
  def self.tar(path,&block)
    Ronin::Support::Archive::Tar::Writer.open(path,&block)
  end

  #
  # Opens the zip archive file for reading.
  #
  # @param [String] path
  #   The path to the file to read.
  #
  # @yield [zip]
  #   If a block is given, it will be passed the zip reader object.
  #
  # @yieldparam [Ronin::Support::Archive::Zip::Reader] zip
  #   The zip reader object.
  #
  # @return [Ronin::Support::Archive::Zip::Reader]
  #   The zip reader object.
  #
  # @api public
  #
  # @since 1.0.0
  #
  def self.unzip(path,&block)
    Ronin::Support::Archive::Zip::Reader.open(path,&block)
  end

  #
  # Opens the zip archive file for writing.
  #
  # @param [String] path
  #   The path to the file to write to.
  #
  # @yield [zip]
  #   If a block is given, it will be passed the zip writer object.
  #
  # @yieldparam [Ronin::Support::Archive::Zip::Writer] zip
  #   The zip writer object.
  #
  # @return [Ronin::Support::Archive::Zip::Writer]
  #   The zip writer object.
  #
  # @api public
  #
  # @since 1.0.0
  #
  def self.zip(path,&block)
    Ronin::Support::Archive::Zip::Writer.open(path,&block)
  end

end