wapmorgan / UnifiedArchive

UnifiedArchive - an archive manager with unified interface for different formats (bundled with cli utility). Supports all formats with basic operations (reading, extracting and creation) and popular formats specific features (compression level, password-protection, comment)
http://wapmorgan.github.io/UnifiedArchive/
MIT License
274 stars 22 forks source link

Compress no longer available #30

Open jasonhoule opened 2 years ago

jasonhoule commented 2 years ago

Describe the bug The compress command is no longer available on Debian based systems. It still appears to be available in Unix and BSD systems. In LzwStreamWrapp::checkBinary() there is a check for both compress and uncompress. When attempting to extract a .tar.Z file the extract fails because of the isBinaryAvailable() check but uncompress is in fact still available.

The archive xmlfeed_lic475-2021_09_24.tar.Z could not be extracted. compress and uncompress commands are required

Configration (please complete the following information):

To Reproduce Attempt to extract a LZW compressed .tar.Z file on newer debian systems where compress is not available or installable.

Expected behavior Perhaps there could be a separate check. If writing to the archive then check for compress? Please take a look at the below. If that works for you then I can submit a pull request

Possible Fix

/**
     * @throws \Exception
     */
    protected static function checkBinary($write = false)
    {
        if (self::$installed === null) {
            if (strncasecmp(PHP_OS, 'win', 3) === 0) {
                self::$installed = false;
            } else {
                self::exec('command -v compress', $output);
                if ($write && empty($output)) {
                    self::$installed = false;
                } else {
                    self::exec('command -v uncompress', $output);
                    if (empty($output)) {
                        self::$installed = false;
                    } else {
                        self::$installed = true;
                    }
                }
            }
        }
    }
/**
     * @param $data
     * @return bool|int
     */
    public function stream_write($data)
    {
        $this->checkBinary(true);
        if (self::$installed === false)
            throw new \Exception('compress and uncompress commands are required');
        $this->writtenBytes += strlen($data);
        if ($this->tmp !== null) {
            $fp = fopen($this->tmp, 'w'.(strpos($this->mode, 'b') !== 0 ? 'b'
                : null));
            fseek($fp, $this->pointer);
            $count = fwrite($fp, $data);
            $this->pointer += $count;
            fclose($fp);

            return $count;
        } else {
            $count = strlen($data);
            $prefix = substr($this->data, 0, $this->pointer);
            $postfix = substr($this->data, ($this->pointer + $count));
            $this->data = $prefix.$data.$postfix;
            $this->pointer += $count;

            return $count;
        }
    }
wapmorgan commented 2 years ago

@jasonhoule waiting for pr