• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Zlib compression
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zlib compression


  • Subject: Re: Zlib compression
  • From: Alastair Houghton <email@hidden>
  • Date: Tue, 24 Feb 2004 11:03:46 +0000

On 21 Feb 2004, at 22:34, Andrew Merenbach wrote:

> I wish to use zlib to compress a file, and have code below for a small
> file (mbox) that exists. The problem is that the program, when run
> from Xcode, completes the task but crashes itself; the data written,
> additionally, does not appear valid. I could use gzwrite(), but wish
> to make an NSData wrapper (the one already referenced in the archives
> appears to be offline). Any help would be greatly appreciated, as
> this problem has had me banging my head off and on for the past few
> months.

[snip]

> outData = [NSMutableData data];
> zresult = Z_OK;
> while (zresult == Z_OK) {

This bit is wrong:

> zresult = deflate (astream, Z_FINISH);
> [outData appendBytes:(astream->next_out)
> length:(astream->avail_out)];

You need to provide buffer space up-front; zlib doesn't set next_out or
avail_out for you, although it will update them (until the buffer
you've provided is exhausted, at any rate).

Take a look at the documentation for deflate() in zlib.h. Also, I'm
not sure you want the Z_FINISH flag; if you use that, then it tells
zlib to compress the entire input in one go, if there is enough room in
the output buffer... if there isn't enough room, then zlib won't do
anything!

Kind regards,

Alastair.

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Zlib compression (From: Andrew Merenbach <email@hidden>)

  • Prev by Date: Bindings, "behind the scenes" theory...
  • Next by Date: Re: problems in measuring text rendering size
  • Previous by thread: Zlib compression
  • Next by thread: Re: Zlib compression
  • Index(es):
    • Date
    • Thread