Uncompressing a .Z file with PythonInvalid magic number - Can't decompress file with python's gzip moduleHow do I check whether a file exists without exceptions?Calling an external command in PythonWhat are metaclasses in Python?How do I copy a file in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How do I list all files of a directory?Does Python have a string 'contains' substring method?

If a digital camera can be "hacked" in the ransomware sense, how best to protect it?

Are differences between uniformly distributed numbers uniformly distributed?

How would timezones work on a planet 100 times the size of our Earth

How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?

If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?

Is it okay for a ticket seller in the USA to refuse to give you your change, keep it for themselves and claim it's a tip?

Is there a standardised way to check fake news?

Solution to German Tank Problem

Is it feasible to get a hash collision for CRC32, MD-5 and SHA-1 on one file?

Can the ground attached to neutral fool a receptacle tester?

Voltage across a resistor

A torrent of foreign terms

How are you supposed to know the strumming pattern for a song from the "chord sheet music"?

Why isn’t SHA-3 in wider use?

Why is there a large performance impact when looping over an array over 240 elements?

What ability do tools use?

Can "être sur" mean "to be about" ?

Annotating a table with arrows

Bitcoin successfully deducted on sender wallet but did not reach receiver wallet

How can God warn people of the upcoming rapture without disrupting society?

These were just lying around

How can I categorize files in a directory based on their content?

How to create events observer that only call when REST api dispatch events?

Are employers legally allowed to pay employees in goods and services equal to or greater than the minimum wage?



Uncompressing a .Z file with Python


Invalid magic number - Can't decompress file with python's gzip moduleHow do I check whether a file exists without exceptions?Calling an external command in PythonWhat are metaclasses in Python?How do I copy a file in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How do I list all files of a directory?Does Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm trying to uncompress a *.Z file using Python. I downloaded it via FTP (binary mode). The file successfully uncompresses with 7zip (whose "info" on the file says it's of type "Z"). The original file can be found at ftp://cddis.gsfc.nasa.gov/gps/products/1860/igr18600.sp3.Z.



I've read up on the use of the zlib module in Python and have some test code I'm using:



import zlib

comp_data = open('C:Tempigr18600.sp3.Z', 'rb').read()

print(comp_data[0:10])

uncomp_data = zlib.decompress(comp_data)
with open('c:tempigr18600.sp3', 'wb') as f:
f.write(uncomp_data)
f.close()


When I execute this I get the following output:



b'x1fx9dx90#xc6@x91x01#F'
Traceback (most recent call last):
File "test.py", line 7, in <module>
uncomp_data = zlib.decompress(comp_data)
zlib.error: Error -3 while decompressing data: incorrect header check


zlib clearly doesn't like the header. The first couple of bytes appear to match the proper magic number sequence 0x1F9d for a compressed file (per https://en.wikipedia.org/wiki/List_of_file_signatures).



In a pinch I can work around this by shelling out to 7zip directly. But I was hoping to find a pure Python type of answer. Despite spending most of the day googling for an answer (or this error message) I haven't had much luck. Perhaps my search skills are atrophying?










share|improve this question


























  • The link also mentions about 7-Zip File Format as 37 7A BC AF 27 1C.

    – Fredrick Gauss
    Oct 3 '15 at 10:57

















3















I'm trying to uncompress a *.Z file using Python. I downloaded it via FTP (binary mode). The file successfully uncompresses with 7zip (whose "info" on the file says it's of type "Z"). The original file can be found at ftp://cddis.gsfc.nasa.gov/gps/products/1860/igr18600.sp3.Z.



I've read up on the use of the zlib module in Python and have some test code I'm using:



import zlib

comp_data = open('C:Tempigr18600.sp3.Z', 'rb').read()

print(comp_data[0:10])

uncomp_data = zlib.decompress(comp_data)
with open('c:tempigr18600.sp3', 'wb') as f:
f.write(uncomp_data)
f.close()


When I execute this I get the following output:



b'x1fx9dx90#xc6@x91x01#F'
Traceback (most recent call last):
File "test.py", line 7, in <module>
uncomp_data = zlib.decompress(comp_data)
zlib.error: Error -3 while decompressing data: incorrect header check


zlib clearly doesn't like the header. The first couple of bytes appear to match the proper magic number sequence 0x1F9d for a compressed file (per https://en.wikipedia.org/wiki/List_of_file_signatures).



In a pinch I can work around this by shelling out to 7zip directly. But I was hoping to find a pure Python type of answer. Despite spending most of the day googling for an answer (or this error message) I haven't had much luck. Perhaps my search skills are atrophying?










share|improve this question


























  • The link also mentions about 7-Zip File Format as 37 7A BC AF 27 1C.

    – Fredrick Gauss
    Oct 3 '15 at 10:57













3












3








3


1






I'm trying to uncompress a *.Z file using Python. I downloaded it via FTP (binary mode). The file successfully uncompresses with 7zip (whose "info" on the file says it's of type "Z"). The original file can be found at ftp://cddis.gsfc.nasa.gov/gps/products/1860/igr18600.sp3.Z.



I've read up on the use of the zlib module in Python and have some test code I'm using:



import zlib

comp_data = open('C:Tempigr18600.sp3.Z', 'rb').read()

print(comp_data[0:10])

uncomp_data = zlib.decompress(comp_data)
with open('c:tempigr18600.sp3', 'wb') as f:
f.write(uncomp_data)
f.close()


When I execute this I get the following output:



b'x1fx9dx90#xc6@x91x01#F'
Traceback (most recent call last):
File "test.py", line 7, in <module>
uncomp_data = zlib.decompress(comp_data)
zlib.error: Error -3 while decompressing data: incorrect header check


zlib clearly doesn't like the header. The first couple of bytes appear to match the proper magic number sequence 0x1F9d for a compressed file (per https://en.wikipedia.org/wiki/List_of_file_signatures).



In a pinch I can work around this by shelling out to 7zip directly. But I was hoping to find a pure Python type of answer. Despite spending most of the day googling for an answer (or this error message) I haven't had much luck. Perhaps my search skills are atrophying?










share|improve this question
















I'm trying to uncompress a *.Z file using Python. I downloaded it via FTP (binary mode). The file successfully uncompresses with 7zip (whose "info" on the file says it's of type "Z"). The original file can be found at ftp://cddis.gsfc.nasa.gov/gps/products/1860/igr18600.sp3.Z.



I've read up on the use of the zlib module in Python and have some test code I'm using:



import zlib

comp_data = open('C:Tempigr18600.sp3.Z', 'rb').read()

print(comp_data[0:10])

uncomp_data = zlib.decompress(comp_data)
with open('c:tempigr18600.sp3', 'wb') as f:
f.write(uncomp_data)
f.close()


When I execute this I get the following output:



b'x1fx9dx90#xc6@x91x01#F'
Traceback (most recent call last):
File "test.py", line 7, in <module>
uncomp_data = zlib.decompress(comp_data)
zlib.error: Error -3 while decompressing data: incorrect header check


zlib clearly doesn't like the header. The first couple of bytes appear to match the proper magic number sequence 0x1F9d for a compressed file (per https://en.wikipedia.org/wiki/List_of_file_signatures).



In a pinch I can work around this by shelling out to 7zip directly. But I was hoping to find a pure Python type of answer. Despite spending most of the day googling for an answer (or this error message) I haven't had much luck. Perhaps my search skills are atrophying?







python zlib compression






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 3 '15 at 10:54









mpromonet

6,97010 gold badges39 silver badges68 bronze badges




6,97010 gold badges39 silver badges68 bronze badges










asked Oct 3 '15 at 10:02









Tom JohnsonTom Johnson

9171 gold badge7 silver badges22 bronze badges




9171 gold badge7 silver badges22 bronze badges















  • The link also mentions about 7-Zip File Format as 37 7A BC AF 27 1C.

    – Fredrick Gauss
    Oct 3 '15 at 10:57

















  • The link also mentions about 7-Zip File Format as 37 7A BC AF 27 1C.

    – Fredrick Gauss
    Oct 3 '15 at 10:57
















The link also mentions about 7-Zip File Format as 37 7A BC AF 27 1C.

– Fredrick Gauss
Oct 3 '15 at 10:57





The link also mentions about 7-Zip File Format as 37 7A BC AF 27 1C.

– Fredrick Gauss
Oct 3 '15 at 10:57












1 Answer
1






active

oldest

votes


















4














Python does not have the equivalent of Unix uncompress available in a module, which is what you'd need to decompress a .Z file. You would either need to a) shell out to the Unix compress command, b) shell out to gzip, c) shell out to 7-zip (both gzip and 7-zip have the ability to decompress .Z files), d) modify the original uncompress code in C and link that to Python (the code is available online), or e) write your own LZW decompressor in native Python.



For d), you can find some C code I wrote to do this job in this answer on mathematica.stackexchange.com. See the unlzw() function.






share|improve this answer






















  • 1





    Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

    – Tom Johnson
    Oct 4 '15 at 11:00






  • 4





    I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

    – unclemeat
    May 26 '16 at 0:18











  • @unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

    – Tom Johnson
    Jul 7 '16 at 14:12










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32921263%2funcompressing-a-z-file-with-python%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Python does not have the equivalent of Unix uncompress available in a module, which is what you'd need to decompress a .Z file. You would either need to a) shell out to the Unix compress command, b) shell out to gzip, c) shell out to 7-zip (both gzip and 7-zip have the ability to decompress .Z files), d) modify the original uncompress code in C and link that to Python (the code is available online), or e) write your own LZW decompressor in native Python.



For d), you can find some C code I wrote to do this job in this answer on mathematica.stackexchange.com. See the unlzw() function.






share|improve this answer






















  • 1





    Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

    – Tom Johnson
    Oct 4 '15 at 11:00






  • 4





    I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

    – unclemeat
    May 26 '16 at 0:18











  • @unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

    – Tom Johnson
    Jul 7 '16 at 14:12















4














Python does not have the equivalent of Unix uncompress available in a module, which is what you'd need to decompress a .Z file. You would either need to a) shell out to the Unix compress command, b) shell out to gzip, c) shell out to 7-zip (both gzip and 7-zip have the ability to decompress .Z files), d) modify the original uncompress code in C and link that to Python (the code is available online), or e) write your own LZW decompressor in native Python.



For d), you can find some C code I wrote to do this job in this answer on mathematica.stackexchange.com. See the unlzw() function.






share|improve this answer






















  • 1





    Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

    – Tom Johnson
    Oct 4 '15 at 11:00






  • 4





    I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

    – unclemeat
    May 26 '16 at 0:18











  • @unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

    – Tom Johnson
    Jul 7 '16 at 14:12













4












4








4







Python does not have the equivalent of Unix uncompress available in a module, which is what you'd need to decompress a .Z file. You would either need to a) shell out to the Unix compress command, b) shell out to gzip, c) shell out to 7-zip (both gzip and 7-zip have the ability to decompress .Z files), d) modify the original uncompress code in C and link that to Python (the code is available online), or e) write your own LZW decompressor in native Python.



For d), you can find some C code I wrote to do this job in this answer on mathematica.stackexchange.com. See the unlzw() function.






share|improve this answer















Python does not have the equivalent of Unix uncompress available in a module, which is what you'd need to decompress a .Z file. You would either need to a) shell out to the Unix compress command, b) shell out to gzip, c) shell out to 7-zip (both gzip and 7-zip have the ability to decompress .Z files), d) modify the original uncompress code in C and link that to Python (the code is available online), or e) write your own LZW decompressor in native Python.



For d), you can find some C code I wrote to do this job in this answer on mathematica.stackexchange.com. See the unlzw() function.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 13 '17 at 12:55









Community

11 silver badge




11 silver badge










answered Oct 3 '15 at 15:39









Mark AdlerMark Adler

61.9k8 gold badges72 silver badges115 bronze badges




61.9k8 gold badges72 silver badges115 bronze badges










  • 1





    Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

    – Tom Johnson
    Oct 4 '15 at 11:00






  • 4





    I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

    – unclemeat
    May 26 '16 at 0:18











  • @unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

    – Tom Johnson
    Jul 7 '16 at 14:12












  • 1





    Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

    – Tom Johnson
    Oct 4 '15 at 11:00






  • 4





    I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

    – unclemeat
    May 26 '16 at 0:18











  • @unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

    – Tom Johnson
    Jul 7 '16 at 14:12







1




1





Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

– Tom Johnson
Oct 4 '15 at 11:00





Thanks Mark. Appreciate all your hard work on zlib. Good to hear I wasn't missing something obvious. I'll shell out to 7-zip for now and begin investigating d and e for my own edification.

– Tom Johnson
Oct 4 '15 at 11:00




4




4





I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

– unclemeat
May 26 '16 at 0:18





I went with option e. Thanks for your help, Mark. github.com/umeat/unlzw

– unclemeat
May 26 '16 at 0:18













@unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

– Tom Johnson
Jul 7 '16 at 14:12





@unclemeat, thanks for tackling the pure python implementation. I'll give your's a try for my application as well.

– Tom Johnson
Jul 7 '16 at 14:12








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32921263%2funcompressing-a-z-file-with-python%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript