File Name form NSFileHandle - iphone

I am using an third party SDK for file handling, they have given some handles for file open, file read, file write. When i create the object of wrapper of that SDK using file path its calls those handle methods (File open, file read etc.).
I want to change the data of file at the time of reading it. But the SDK open multiple supporting files so i am not able to find is it my file in read state or some other file.
They have provided the object of NSFileHandle in there read method is there is any way i can find out is it my file or supporting file using file handle object or is there is any other way around.
Please suggest me the solutions.
Regards:

Related

Reading/writing data to encrypted custom file type

I'd like to create a custom file type, say, .cstm, and be able to create .cstm files on the mac, and read them on the iPhone.
I want the .cstm file to contain XML data. Currently I've got the mac app to successfully make .xml files and the iPhone app to successfully read .xml files, but I'd like to create a proprietary custom file type.
How would I go about doing this? I know how to allow the iPhone app to open a custom file type, but that's as far as I know.
Thanks!
You don't need anything special per se. You can just save and load to the URL with the ctsm extension. To support your app automatically launching as an editor of that extension in OSX, you will want to add an entry to your Info.plist file CFBundleDocumentTypes array entry declaring your app as an editor of that extension
https://developer.apple.com/library/mac/#documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-101685-TPXREF107

Appending data to a file on a FTP server in iOS

After learning the basics from Apple's SimpleFTPSample project, I'm trying to append a string to the end of a .txt file on my FTP server. I successfully managed to overwrite an existing file with a custom string, but I suspect that the kCFStreamPropertyAppendToFile property that defines whether the file will be overwritten or appended is not available in iOS.
What is the recommended way to do so in iOS?
Eventually I ended up downloading the file's content using HTTP (it's much faster than FTP). Next, appending the string to the file's content and then uploading the file to the server using FTP.
This might not be the best solution, but it does solve the problem.

Can I download and rename a file from .abc to .json in my app?

I would like to take a json file (.json) and rename it to my app's file type (.abc) and then attach it to an email and then open this file up in another instance of my app and then read this .json file.
Would this be possible? i.e. can I take this file save it and rename it back to .json and then read it using a json parser all within my running iOS app?
Short answer is yes, but why bother with extensions? Anyways, take a look at these NSFileManager methods :
– replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:
– moveItemAtURL:toURL:error:
– moveItemAtPath:toPath:error:

Identify docx pptx xlsx and other msoffice files correctly rather than applicaton/zip

Currently, im working on a perl script that should allow a file to be uploaded, and then process it, and then send it to a printer.
http://code.google.com/p/web-printer-http/
Apparently, both zip and microsoft office files ending in "...x" identify themselves as application/zip when using /usr/bin/file.
Any idea to differ them?
The differing should not be based on extension since the uploading system may be unabe to use extensions (like mobile phones and such).
Rather, it should judge the content entirely based on file content.
There's no way to distinguish between a .zip file and an Office Open XML file (like .docx, xslx, .pptx, etc) without peeking inside the zip.
All of the various open XML formats use .ZIP compression. Therefore they are zip files.
If the zipfile conforms to the Open Packaging Convention, then it may also be an Open XML (Office) document.
A good heuristic is if the zip file contains a file called /[Content_Types].xml, then it is an OPC file. To determine if the zip file contains a file of that name, you must read the zipfile directory. Use a zip library to do that.

Naming a file downloaded from url in iPhone

I would like to save a file downloaded from the internet in iPhone.
Can I use the url as the file name? If not, what transformation should I apply to the url to obtain a valid file name?
I need to find the local copy of the file later using its url.
Edit: Not asking where or how to write a file to disk. The question is limited to getting a valid file name from an url.
Can I use the url as the file name?
You can use just about anything you want for a file name. As long as it's a valid file name for the underlying file system.
If
not, what transformation should I
apply to the url to obtain a valid
file name?
This is unanswerable because there's no way to specify what "valid" means here.
I need to find the local copy of the
file later using its url.
You probably want to save it to your application's Documents directory. There already are plenty of questions relating to saving files on iPhone here on Stack Overflow, and I urge you to read some of them.
For lack of a better method, I'm using a persistent dictionary to map the urls to unique names.