Library for decoding a zip file in chunk - iphone

Hi fellow overflowers,
i need to decode a large zip file (around 20mb) on the ipad. Is there a way to parse the zip file in chunks?
Ideally i would like to pass the decoder (let's say) 512k of data at time, and get back a chunk of decoded data, because i have a feeling that loading all the file in memory and then decompress it could lead to severe memory problems.
A pointer to some incremental decoding libraries would be nice!
Thanks,
Giuliano
UPDATE: the link provided by Matt in his answer worked fine for me ;)

Have you tried objective-zip? http://code.google.com/p/objective-zip/
There's an example near the bottom of http://code.google.com/p/objective-zip/wiki/GettingStarted, showing how to read big files.

I have achieve unzipping files using GCD. This examples uses unzipping of files in different thread and when done it notifies main thread and main thread updates the information.... Hope this may also be solution to your problem....
http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

Related

File Uploading in Sakai

I want to know if there is a 'right' way to make file uploads through custom tools.
I've seen the https://confluence.sakaiproject.org/display/BOOT/File+Uploads+with+RSF guide and it seens ok, but It stops with the file in memory with no further info. I can built a random file upload code but I want to make it Sakai-friendly (Using ContentHosting and Resources service?)
Any hints?
Thanks
The link you provided for the first part is a good example of how to get the upload initially processed. Going through RequestFilter will get your files validated, but you can use whatever method you want to upload it.
For the second part, I'd look at the ContentHosting webservice (createContentItem) for an example of how to add a file from a byte[] in memory after you've uploaded it.
These methods in ContentHostingService also accept InputStream as a parameter as of 2.7 (KNL-325), so you don't have to store the entire file in memory and can stream it as you're uploading, which you should do if the files are of any reasonable size.

VB to download torrent, deflate gzipped section selectively

Apologies if this is a basic question, i'm a very casual programmer.
I'm writing a program which will search for torrents, grab them based on certain criteria (one being that they are indicated as freeware, you'll be pleased to hear) and then throw them over to utorrent. I'm getting stuck downloading the .torrent file, because, I believe, of the encoding.
I've worked out thus far that the bulk of the top of the file can be gzip deflated on the fly using HTTPrequest - but it seems that half-way through the file, something changes - and looking in a hex editor at a .torrent i've grabbed from a site directly versus the one I download here, everything is identical up to a point, then all is totally different.
If i'm being vague i'm afraid it's because i'm making this all up as I go along! Is it likely that the encoding / compression in a torrent file would change part way through, and how could I catch this in VB to avoid corrupting the latter half?
Thanks very much in advance,
Dan

Download and unpack a *.tgz file to a subdirectory of the Documents directory

There very well may be an answer to this already on SO, but I'm not familiar enough with compression formats to know if they're applicable to my case. So here's what I need:
1) Download a *.tgz file that is greater than 200MB.
2) Unpack it to a specified subdirectory of the Documents folder.
I know how to make the connection and begin downloading. But how do I download to an actual file (rather than storing it in memory), and once this download is complete how do I unpack it to my desired location?
To save the downloaded data to a file, see this SO-question and answer(s): The easiest way to write NSData to a file
To uncompress .tgz-files, see this question and answer(s): "Untar" file on iPhone
To download large files, see this question and answer(s): How to download large files using objective c on iphone
(Google is an awesome tool, really.)
Just as a sidenote, an app shouldn't download 200MB of data. It is time- and bandwith consuming and may cause Apple to reject your app.
Forget NSURLConnection; use ASIHTTPConnection (google it) which has an easy save to file option. (And resumes failed downloads too)
I don't know the answer to tar/gzip. My application uses zips instead and http://code.google.com/p/ziparchive/wiki/PageName does the trick.

downloading big size(In MB) .txt files using NSURLConnection

I'm downloading .txt files using NSURLConnection. Small size (in KB's) files are downloading perfectly but when i downloading big size(In MB) file, it always downloaded with corrupt data.
Sometimes big size .txt files are downloaded. But when i fetch those .txt file programmatically, it shows null content in it.
Please help.....
Thanks in advance.
You should check out the ASIHTTPRequest wrapper classes for HTTP request. They make the download of big sized files easy as they allow to download the files directly to the file system. I am currently using these wrapper classes on a project and I can assure you that they make your life a lot easier.

Where to cache remote image files in iOS?

I am planning to cache the images from a server and use show it as a sort slide show in my App. I would be asynchronously loading the images.
I have two options:
Either to cache the images as a File and use it whenever necessary.
Cache the images objects in memory and use it when ever necessary and write it in to files when Application quits.
Which one would be better?
Please let me know if you you have any kind of suggestions regarding caching images.
Your second approach has 2 major flaws:
If there's too many images then your application will get low memory warning and you'll have to dispose your images from memory anyway
It's also not a good idea to save all images to file on application quit - it is not guaranteed that your saving code will finish on application exit (e.g. if it takes too long system may just terminate your app and your images will be lost)
I'd suggest saving images to files right after you download them and keep in memory reasonable number of images you need to show without visible delay (loading extra images when required and disposing of unnecessary ones)
I would recommend you the first option. Leaves you more flexibility, e.g. when the data size increases the memory size.
I'd do it like this: Have a NSMutableDictionary with the cached images (as UIImage objects). If the image is not in the cache, look whether it's available as a file. If it's not available as a file, load it, put it into your dictionary and also write it to a file.
As for where to write the files to: you can either use the NSTemporaryDirectory() or create a directory inside your NSLibraryDirectory (use NSSearchPathForDirectoriesInDomains to locate it). The later has the advantage/disadvantage that it will be in the iTunes backup (whether that's an advantage or not depends on the use case). Using the Library directory is Apple's recommended way of storing data that is backed up but does not appear in the iTune's file exchange thingy (Documents directory).
I have started using EGOImageView to handle my caching; it's very versatile and handles the intricacies of caching for you.
It works very well for pulling images via http, you can find it on the EGO developer website here
http://developers.enormego.com/
For image caching solution on iOS platform, you might want to consider SDWebImage framework available at: https://github.com/rs/SDWebImage. It is very easy to integrate and takes care of all your image caching worries.: read more about the working here: https://github.com/rs/SDWebImage#readme
We recently picked this up for our app and it works great.