Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress no longer available #30

Open
jasonhoule opened this issue Nov 19, 2021 · 1 comment
Open

Compress no longer available #30

jasonhoule opened this issue Nov 19, 2021 · 1 comment
Assignees
Labels

Comments

@jasonhoule
Copy link
Contributor

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):

  • OS: Ubuntu 20.04.3
  • Version of library: 1.4.14

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 wapmorgan self-assigned this Dec 21, 2021
@wapmorgan wapmorgan added the bug label Dec 21, 2021
@wapmorgan
Copy link
Owner

@jasonhoule waiting for pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants