PDA

View Full Version : NSData & zcat


unknown
2006.10.20, 11:02 AM
Is there an easy way to turn an NSData into a zipped version of that NSData and more importantly to turn a zipped NSData into a decompressed version,
the NSData I have is viewable with zcat, but I was hoping there would be a better way than using pipes and process and hopefully not having to get zlib.

unknown
2006.10.20, 12:06 PM
ugh looks like zlib doesnt even do it

# Can zlib handle .Z files?

No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt the code of uncompress on your own.

any ideas?

Steven
2006.10.20, 04:42 PM
.Z is a file compressed with the UNIX compress utility - you're more likely to be using gzip or bzip, which I believe should be handled by zlib or libbz2 respectively.

unknown
2006.10.20, 04:53 PM
no.. I am dealing with .Z files. the kind that you can read with zcat.

Steven
2006.10.21, 04:59 AM
Well, zcat reads .gz files too, so I misunderstood. :)
You're probably stuck with the suggestions it gave - namely piping or finding a library that does it.

unknown
2006.10.21, 09:41 AM
oh well, Ill get coding then :) Thanks for the advice.

unknown
2006.10.21, 10:43 AM
I was hoping to just write the data into the stdin of the process and read stdout but I cant get popen to work :(
Is there anything obviously wrong im doing here?


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv) {
FILE * proc;
char myeof = EOF;

proc = popen("banner", "a+");

if(!proc) {
printf("!proc\n");
return 0;
}

printf("wrote\n");
fwrite("hello world", 11, 1, proc);

printf("reading\n");
while(1) {
printf(":%c\n", fgetc(proc));
}

return 0;
}

ThemsAllTook
2006.10.21, 02:16 PM
The type argument is a pointer to a null-terminated string which must be`r' for reading, `w' for writing, or `r+' for reading and writing.
proc = popen("banner", "r+");