Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:39:29+00:00 2026-05-29T16:39:29+00:00

Possible Duplicate: Deflate command line tool Yes, I know I can use PHP itself

  • 0

Possible Duplicate:
Deflate command line tool

Yes, I know I can use PHP itself on the shell, but I need this functionality in a script that is deployed before PHP is available.

I’ve tried gzip and unzip but either my parameters are incorrect or they plain just don’t use the same compression.

I want to use this in a bash script. Going into a higher level scripting language isn’t an option.


I wrote the following PHP script for testing purposes:

#!/usr/bin/php
<?
  $contents = file_get_contents( $argv[1] );
  $data = gzuncompress( $contents );
  echo substr( $data, 0, 20 ) . "\n";
?>

This outputs what I expect (the beginning of the decoded data).

If I pass the same file to gunzip:

$ gunzip -c data
gzip: data: not in gzip format

If I try unzip:

$ unzip data
Archive:  data
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of data2 or
        data2.zip, and cannot find data2.ZIP, period.

As suggested, and given that there is no other practical way, I went with the solution presented in the related question.
But given that I wanted to avoid moving to another scripting language (and introducing another dependency) I went with all of them:

_uncompressedData=
if hash perl 2>&-; then
  echo "Using Perl for decompression..." >&2
  _uncompressedData=$(perl -MCompress::Zlib -e 'undef $/; print uncompress(<>)' < compressed.bin || true)
elif hash ruby 2>&-; then
  echo "Using Ruby for decompression..." >&2
  _uncompressedData=$(ruby -rzlib -e 'print Zlib::Inflate.new.inflate(STDIN.read)' < compressed.bin || true)
elif hash php 2>&-; then
  echo "Using PHP for decompression..." >&2
  _uncompressedData=$(php -r "echo gzuncompress(file_get_contents('php://stdin'));" < compressed.bin || true)
elif hash python 2>&-; then
  echo "Using Python for decompression..." >&2
  _uncompressedData=$(python -c "import zlib,sys;print zlib.decompress(sys.stdin.read())" < compressed.bin || true)
else
  echo "Unable to find decompressor!" >&2
  exit 1
fi

These 4 versions produced the exact same output with my test cases.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:39:32+00:00Added an answer on May 29, 2026 at 4:39 pm

    The format that gzuncompress expects is the raw zlib format without the gzip header. This is the format you get by default if you use the zlib library’s C API.

    You can uncompress this format using the zpipe command-line utility. The source code for this utility is found in examples/zpipe.c in the zlib source code distribution. But this program is not compiled and installed by default. There are no widely deployed command-line utilities that accept the raw zlib format.

    If you want to use the gzip format instead (the one with the friendly header which gzip & gunzip deal with) from PHP then you need to use gzencode & gzdecode instead of gzcompress & gzuncompress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to: URL re-writing in PHP? How can a website use an
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: Can you call Directory.GetFiles() with multiple filters? Does it possible to get
Possible Duplicate: What is 0x10 in decimal? I notice that Console.WriteLine(18); writes 18, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.