NSData & zcat

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
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.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
ugh looks like zlib doesnt even do it

Quote:# 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?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #3
.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.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
no.. I am dealing with .Z files. the kind that you can read with zcat.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #5
Well, zcat reads .gz files too, so I misunderstood. Smile
You're probably stuck with the suggestions it gave - namely piping or finding a library that does it.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
oh well, Ill get coding then Smile Thanks for the advice.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
I was hoping to just write the data into the stdin of the process and read stdout but I cant get popen to work Sad
Is there anything obviously wrong im doing here?

Code:
#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;
}

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #8
man popen Wrote: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+");
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cannot load NSData from NSUserDefaults groffhibbitz 1 3,407 Jun 25, 2009 10:25 PM
Last Post: SethWillits